Compare commits
13 Commits
b5041ff3e4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcb247834d | ||
|
|
e25cb93bd0 | ||
|
|
87a7ddd137 | ||
|
|
1d90ca08b4 | ||
|
|
6bf8a31b1a | ||
|
|
045cdc8002 | ||
|
|
9a02a3609c | ||
|
|
92cee891c4 | ||
|
|
f3817ca14c | ||
|
|
fd3fa6349b | ||
|
|
c42f26105c | ||
|
|
4406739f56 | ||
|
|
7d49441b4d |
5
BigRoomMyS/.gitignore
vendored
5
BigRoomMyS/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
10
BigRoomMyS/.vscode/extensions.json
vendored
10
BigRoomMyS/.vscode/extensions.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#ifndef __MAIN__
|
|
||||||
#define __MAIN__
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <Wire.h>
|
|
||||||
#include "MHZ19.h"
|
|
||||||
|
|
||||||
#define DEBUG
|
|
||||||
#define MY_DEBUG
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_TRANSPORT_WAIT_READY_MS 5000
|
|
||||||
//#define MY_REPEATER_FEATURE
|
|
||||||
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN (A3) // Error led pin
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN (A2) // Receive led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN (A1) // the PCB, on board LED
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
#include <SoftwareSerial.h> // Remove if using HardwareSerial or non-uno compatabile device
|
|
||||||
#include <HTU21D.h>
|
|
||||||
#include <RunningMedian.h>
|
|
||||||
|
|
||||||
void printDeb(String msg);
|
|
||||||
|
|
||||||
#define RX_PIN 8
|
|
||||||
#define TX_PIN 7
|
|
||||||
#define BAUDRATE 9600
|
|
||||||
|
|
||||||
#define MOTION (3)
|
|
||||||
#define PS (4)
|
|
||||||
#define LED_WHITE (5)
|
|
||||||
#define LED_BLUE (6)
|
|
||||||
MHZ19 myMHZ19;
|
|
||||||
SoftwareSerial mySerial(RX_PIN, TX_PIN);
|
|
||||||
HTU21D myHTU21D(HTU21D_RES_RH10_TEMP13);
|
|
||||||
RunningMedian samples = RunningMedian(5 * sizeof(int));
|
|
||||||
|
|
||||||
//uint8_t periodMinCO2;
|
|
||||||
byte periodMotion;
|
|
||||||
int8_t curDelay;
|
|
||||||
uint16_t spLight, dbLight;
|
|
||||||
uint8_t timeLight;
|
|
||||||
byte levelBlue, levelWhite;
|
|
||||||
bool move, lightWhite;
|
|
||||||
float temp, hum;
|
|
||||||
bool bLamp, wLamp;
|
|
||||||
uint8_t statLamp;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:pro8MHzatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = pro8MHzatmega328
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps =
|
|
||||||
MySensors @ ^2.3.2
|
|
||||||
wifwaf/MH-Z19 @ ^1.5.3
|
|
||||||
enjoyneering/HTU21D @ ^1.2.1
|
|
||||||
featherfly/SoftwareSerial @ ^1.0
|
|
||||||
robtillaart/RunningMedian @ ^0.3.3
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
#include "main.h"
|
|
||||||
|
|
||||||
void presentation();
|
|
||||||
void sendDataI(MyMessage msg, uint32_t status);
|
|
||||||
void sendDataF(MyMessage msg, float status);
|
|
||||||
void sendDataB(MyMessage msg, bool status);
|
|
||||||
|
|
||||||
MyMessage msgTemp(0, V_TEMP);
|
|
||||||
MyMessage msgHum(1, V_HUM);
|
|
||||||
MyMessage msgMove(2, V_TRIPPED);
|
|
||||||
MyMessage msgCO2(3, V_VAR1);
|
|
||||||
MyMessage msgLight(3, V_VAR2);
|
|
||||||
MyMessage msgTimeWork(3, V_VAR3);
|
|
||||||
MyMessage msgTimeMotion(3, V_VAR4);
|
|
||||||
//MyMessage msgPeriodCO2(3, V_VAR5);
|
|
||||||
MyMessage msgWLamp(4, V_DIMMER);
|
|
||||||
MyMessage msgSPLight(5, V_VAR1);
|
|
||||||
MyMessage msgDBLight(5, V_VAR2);
|
|
||||||
MyMessage msgWLight(5, V_VAR3);
|
|
||||||
MyMessage msgTimeLight(5, V_VAR4);
|
|
||||||
|
|
||||||
void before(){
|
|
||||||
pinMode(PS, OUTPUT);
|
|
||||||
digitalWrite(PS, LOW);
|
|
||||||
pinMode(LED_BLUE, OUTPUT);
|
|
||||||
pinMode(LED_WHITE, OUTPUT);
|
|
||||||
digitalWrite(LED_BLUE, HIGH);
|
|
||||||
digitalWrite(LED_WHITE, HIGH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
pinMode(MOTION, INPUT_PULLUP);
|
|
||||||
mySerial.begin(BAUDRATE); // Uno example: Begin Stream with MHZ19 baudrate
|
|
||||||
myMHZ19.begin(mySerial); // *Important, Pass your Stream reference here
|
|
||||||
myMHZ19.autoCalibration(false);
|
|
||||||
|
|
||||||
/*char myVersion[4];
|
|
||||||
myMHZ19.getVersion(myVersion);
|
|
||||||
Serial.print("\nFirmware Version: ");
|
|
||||||
for(byte i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
Serial.print(myVersion[i]);
|
|
||||||
if(i == 1)
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("");
|
|
||||||
Serial.print("Range: ");
|
|
||||||
Serial.println(myMHZ19.getRange());
|
|
||||||
Serial.print("Background CO2: ");
|
|
||||||
Serial.println(myMHZ19.getBackgroundCO2());
|
|
||||||
Serial.print("Temperature Cal: ");
|
|
||||||
Serial.println(myMHZ19.getTempAdjustment());
|
|
||||||
Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") : Serial.println("OFF");*/
|
|
||||||
// periodMinCO2 = loadState(0);
|
|
||||||
// sendDataI(msgPeriodCO2, periodMinCO2);
|
|
||||||
// if(periodMinCO2 == 0) periodMinCO2 = 1;
|
|
||||||
periodMotion = loadState(11);
|
|
||||||
sendDataI(msgTimeMotion, periodMotion);
|
|
||||||
// if(periodMotion == 0) periodMotion = 60;
|
|
||||||
spLight = (loadState(12) << 8) + loadState(13);
|
|
||||||
sendDataI(msgSPLight, spLight);
|
|
||||||
dbLight = (loadState(14) << 8) + loadState(15);
|
|
||||||
sendDataI(msgDBLight, dbLight);
|
|
||||||
levelBlue = loadState(6);
|
|
||||||
levelWhite = loadState(7);
|
|
||||||
// timeLight = loadState(8);
|
|
||||||
// sendDataI(msgTimeWork, timeLight);
|
|
||||||
// Serial.print(F("PeriodCO2:"));Serial.println(periodMinCO2);
|
|
||||||
Serial.print(F("PeriodMove:"));Serial.println(periodMotion);
|
|
||||||
Serial.print(F("SPLight:"));Serial.println(spLight);
|
|
||||||
Serial.print(F("DBLight:"));Serial.println(dbLight);
|
|
||||||
Serial.print(F("BLevel:"));Serial.println(levelBlue);
|
|
||||||
Serial.print(F("WLevel:"));Serial.println(levelWhite);
|
|
||||||
//Serial.print(F("TimeLight:"));Serial.println(timeLight);
|
|
||||||
myHTU21D.begin();
|
|
||||||
curDelay = -1;
|
|
||||||
wLamp = bLamp = false;
|
|
||||||
statLamp = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
static uint32_t cRun = millis();
|
|
||||||
static uint8_t sec = 0;
|
|
||||||
//static uint8_t minuts = 0;
|
|
||||||
|
|
||||||
if(digitalRead(MOTION) > 0){
|
|
||||||
if(curDelay == -1) sendDataB(msgMove, true);
|
|
||||||
move = true;
|
|
||||||
curDelay = periodMotion;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t LightLev = analogRead(A0);
|
|
||||||
samples.add(LightLev);
|
|
||||||
LightLev = samples.getMedian();
|
|
||||||
if ((LightLev < spLight) && move && !bLamp){
|
|
||||||
analogWrite(LED_BLUE, (levelBlue) * 2.55);
|
|
||||||
statLamp |= 0x01;
|
|
||||||
bLamp = true;
|
|
||||||
Serial.println(F("BLamp On"));
|
|
||||||
}
|
|
||||||
else if((LightLev > (spLight + dbLight)) || (move == 0)){
|
|
||||||
//analogWrite(LED_BLUE, 0);
|
|
||||||
digitalWrite(LED_BLUE, LOW);
|
|
||||||
statLamp &= 0xFE;
|
|
||||||
bLamp = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lightWhite && !wLamp){
|
|
||||||
analogWrite(LED_WHITE, (levelWhite) * 2.55);
|
|
||||||
statLamp |= 0x02;
|
|
||||||
wLamp = true;
|
|
||||||
Serial.println(F("WLamp On"));
|
|
||||||
}
|
|
||||||
else if (!lightWhite){
|
|
||||||
//analogWrite(LED_WHITE, 0);
|
|
||||||
digitalWrite(LED_WHITE, LOW);
|
|
||||||
statLamp &= 0xFD;
|
|
||||||
wLamp = false;
|
|
||||||
}
|
|
||||||
if(statLamp > 0) digitalWrite(PS, HIGH);
|
|
||||||
else digitalWrite(PS, LOW);
|
|
||||||
|
|
||||||
|
|
||||||
if((cRun + 1000) <= millis()){ //Once per second
|
|
||||||
cRun = millis();
|
|
||||||
if(curDelay > -1){
|
|
||||||
Serial.println("ADC: " + String(LightLev) + " MV:" + String(move) + " TMv:" + curDelay + " SL:" + String(statLamp) + " PS:" + digitalRead(PS));
|
|
||||||
Serial.println("SPL: " + String(spLight) + " DBL:" + String(dbLight)+ " BL:" + String(bLamp));
|
|
||||||
}
|
|
||||||
sec++;
|
|
||||||
if(curDelay > 0) curDelay--;
|
|
||||||
if(curDelay == 0){
|
|
||||||
sendDataB(msgMove, false);
|
|
||||||
move = false;
|
|
||||||
curDelay = -1;
|
|
||||||
}
|
|
||||||
if((sec + 2) % 30 == 0){
|
|
||||||
temp = myHTU21D.readTemperature();
|
|
||||||
hum = myHTU21D.readCompensatedHumidity();
|
|
||||||
// Serial.println("Temp: " + String(temp));
|
|
||||||
// Serial.println("Hum: " + String(hum));
|
|
||||||
}
|
|
||||||
if(sec == 59){
|
|
||||||
//minuts++;
|
|
||||||
sec = 0;
|
|
||||||
// }
|
|
||||||
// if(minuts == periodMinCO2){
|
|
||||||
int CO2; // Buffer for CO2
|
|
||||||
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
|
|
||||||
|
|
||||||
if(myMHZ19.errorCode == RESULT_OK) // RESULT_OK is an alis for 1. Either can be used to confirm the response was OK.
|
|
||||||
{
|
|
||||||
Serial.println(CO2);
|
|
||||||
sendDataI(msgCO2, CO2);
|
|
||||||
wait(50);
|
|
||||||
}
|
|
||||||
// else{
|
|
||||||
// Serial.println("CO2err:" + String(myMHZ19.errorCode));
|
|
||||||
// }
|
|
||||||
if(temp != HTU21D_ERROR){
|
|
||||||
// Serial.println("Send");
|
|
||||||
|
|
||||||
// Serial.println("Temp: " + String(temp));
|
|
||||||
// Serial.println("Hum: " + String(hum));
|
|
||||||
sendDataF(msgTemp, temp);
|
|
||||||
wait(50);
|
|
||||||
sendDataF(msgHum, hum);
|
|
||||||
wait(50);
|
|
||||||
}
|
|
||||||
sendDataF(msgTimeWork, cRun / 60000.0);
|
|
||||||
wait(50);
|
|
||||||
sendDataI(msgLight, LightLev);
|
|
||||||
//minuts = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
sendSketchInfo(F("MidRoom"), F("1.0"));
|
|
||||||
present(0, S_TEMP, F("Temp"));
|
|
||||||
present(1, S_HUM, F("Humid"));
|
|
||||||
present(2, S_MOTION, F("Motion"));
|
|
||||||
present(3, S_CUSTOM, F("CO2_Light_Time"));
|
|
||||||
present(4, S_DIMMER, F("White Light"));
|
|
||||||
present(5, S_CUSTOM, F("Blue Light SP_DB"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void receive(const MyMessage &message)
|
|
||||||
{
|
|
||||||
// if((message.sensor == 3) && (message.type == V_VAR5)){
|
|
||||||
// periodMinCO2 = message.getByte();
|
|
||||||
// saveState(0, periodMinCO2);
|
|
||||||
// }
|
|
||||||
if((message.sensor == 3) && (message.type == V_VAR4)){
|
|
||||||
periodMotion = message.getULong();
|
|
||||||
printDeb("PerMot:" + String(periodMotion));
|
|
||||||
saveState(11, periodMotion);
|
|
||||||
}
|
|
||||||
if((message.sensor == 4) && (message.type == V_DIMMER)){
|
|
||||||
levelWhite = message.getULong();
|
|
||||||
printDeb("LevelW:" + String(dbLight));
|
|
||||||
saveState(7, levelWhite);
|
|
||||||
if(wLamp) analogWrite(LED_WHITE, (levelWhite) * 2.55);
|
|
||||||
}
|
|
||||||
if((message.sensor == 5) && (message.type == V_VAR3)){
|
|
||||||
levelBlue = message.getULong();
|
|
||||||
printDeb("LevelB:" + String(levelBlue));
|
|
||||||
saveState(6, levelBlue);
|
|
||||||
if(bLamp) analogWrite(LED_BLUE, (levelBlue) * 2.55);
|
|
||||||
}
|
|
||||||
if((message.sensor == 4) && (message.type == V_STATUS)){
|
|
||||||
lightWhite = message.getBool();
|
|
||||||
//saveState(6, lightWhite);
|
|
||||||
}
|
|
||||||
if((message.sensor == 5) && (message.type == V_VAR1)){
|
|
||||||
spLight = message.getULong();
|
|
||||||
printDeb("SPL:" + String(spLight));
|
|
||||||
saveState(12, (spLight >> 8) & 0xFF);
|
|
||||||
saveState(13, spLight & 0xFF);
|
|
||||||
|
|
||||||
}
|
|
||||||
if((message.sensor == 5) && (message.type == V_VAR2)){
|
|
||||||
dbLight = message.getULong();
|
|
||||||
printDeb("DBL:" + String(dbLight));
|
|
||||||
saveState(14, (dbLight >> 8) & 0xFF);
|
|
||||||
saveState(15, dbLight & 0xFF);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendDataI(MyMessage msg, uint32_t val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val), true);
|
|
||||||
if(!send_data)
|
|
||||||
wait(500, C_SET, msg.type);
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendDataF(MyMessage msg, float val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val, 2), true);
|
|
||||||
if(!send_data)
|
|
||||||
wait(500, C_SET, msg.type);
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendDataB(MyMessage msg, bool val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val), true);
|
|
||||||
if(!send_data)
|
|
||||||
wait(500, C_SET, msg.type);
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printDeb(String msg)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.println(msg);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -31,7 +31,7 @@ PWMrelay relay(TRIAC_PIN, true); // реле на 15 пине
|
|||||||
|
|
||||||
#define WIFI_SSID "wf-home"
|
#define WIFI_SSID "wf-home"
|
||||||
#define WIFI_PASSWORD "0ndthnrf"
|
#define WIFI_PASSWORD "0ndthnrf"
|
||||||
#define MQTT_SERV "192.168.1.111"
|
#define MQTT_SERV "192.168.1.10"
|
||||||
#define HOSTNAME "Box-balkon"
|
#define HOSTNAME "Box-balkon"
|
||||||
|
|
||||||
#define TOPIC "home/box/"
|
#define TOPIC "home/box/"
|
||||||
|
|||||||
@@ -9,12 +9,11 @@
|
|||||||
; https://docs.platformio.org/page/projectconf.html
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
platform = espressif32
|
platform = espressif32@6.11.0
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
robtillaart/RunningMedian @ ^0.3.3
|
robtillaart/RunningMedian @ ^0.3.3
|
||||||
lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
|
lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
|
||||||
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
||||||
climateguard/ClimateGuard RadSens @ ^1.1.3
|
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
|
|||||||
@@ -26,11 +26,6 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
|
|
||||||
#include "CG_RadSens.h"
|
|
||||||
|
|
||||||
CG_RadSens radSens(RS_DEFAULT_I2C_ADDRESS); /*Constructor of the class ClimateGuard_RadSens1v2,
|
|
||||||
sets the address parameter of I2C sensor.
|
|
||||||
Default address: 0x66.*/
|
|
||||||
|
|
||||||
typedef struct message {
|
typedef struct message {
|
||||||
float temperature;
|
float temperature;
|
||||||
@@ -102,9 +97,6 @@ void setup() {
|
|||||||
WiFi.mode(WIFI_MODE_APSTA);
|
WiFi.mode(WIFI_MODE_APSTA);
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
|
|
||||||
radSens.init();
|
|
||||||
radSens.setSensitivity(105);
|
|
||||||
|
|
||||||
oldmov = 0;
|
oldmov = 0;
|
||||||
lamp = false;
|
lamp = false;
|
||||||
cRun = millis();
|
cRun = millis();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
default_envs = lolin
|
default_envs = lolin
|
||||||
|
|
||||||
[env:lolin]
|
[env:lolin]
|
||||||
platform = espressif32
|
platform = espressif32@6.11.0
|
||||||
board = lolin32
|
board = lolin32
|
||||||
framework = arduino
|
framework = arduino
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -22,9 +22,11 @@ lib_deps =
|
|||||||
robtillaart/RunningMedian @ ^0.3.4
|
robtillaart/RunningMedian @ ^0.3.4
|
||||||
wifwaf/MH-Z19 @ ^1.5.3
|
wifwaf/MH-Z19 @ ^1.5.3
|
||||||
plerup/EspSoftwareSerial @ ^6.15.2
|
plerup/EspSoftwareSerial @ ^6.15.2
|
||||||
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
; ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
||||||
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
esphome/AsyncTCP-esphome @ ^2.1.4
|
||||||
ayushsharma82/AsyncElegantOTA @ ^2.2.6
|
ottowinter/ESPAsyncWebServer-esphome @ ^3.1.0
|
||||||
|
https://github.com/qdrk/AsyncElegantOTA.git
|
||||||
|
; ayushsharma82/AsyncElegantOTA @ ^2.2.8
|
||||||
ayushsharma82/WebSerial @ ^1.3.0
|
ayushsharma82/WebSerial @ ^1.3.0
|
||||||
plerup/EspSoftwareSerial @ ^8.1.0
|
plerup/EspSoftwareSerial @ ^8.1.0
|
||||||
powerbroker2/SerialTransfer @ ^3.1.3
|
powerbroker2/SerialTransfer @ ^3.1.3
|
||||||
|
|||||||
@@ -10,11 +10,7 @@ TimerHandle_t wifiReconnectTimer;
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* ssid1 = "wf-home";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
const char* password1 = "0ndthnrf";
|
|
||||||
const char* ssid2 = "BR";
|
|
||||||
const char* password2 = "499727479o";
|
|
||||||
const char* mqtt_server = "192.168.1.111";
|
|
||||||
|
|
||||||
void connectToWifi();
|
void connectToWifi();
|
||||||
//void connectToMqtt();
|
//void connectToMqtt();
|
||||||
@@ -127,7 +123,7 @@ void setup() {
|
|||||||
#define SDA 33 //assign new SDA pin to GPIO1/D2/0TX for all slaves on i2c bus
|
#define SDA 33 //assign new SDA pin to GPIO1/D2/0TX for all slaves on i2c bus
|
||||||
#define SCL 32 //assign new SCL pin to GPIO3/D7/0RX for all slaves on i2c bus
|
#define SCL 32 //assign new SCL pin to GPIO3/D7/0RX for all slaves on i2c bus
|
||||||
Wire.begin(SDA, SCL);
|
Wire.begin(SDA, SCL);
|
||||||
if (!htu.begin(SDA, SCL)) {
|
if (!htu.begin(&Wire)) {
|
||||||
Serial.println("Couldn't find sensor!");
|
Serial.println("Couldn't find sensor!");
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,4 @@ lib_deps =
|
|||||||
ottowinter/ESPAsyncWebServer-esphome @ ^3.0.0
|
ottowinter/ESPAsyncWebServer-esphome @ ^3.0.0
|
||||||
lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
|
lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
|
||||||
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
||||||
https://github.com/climateguard/RadSens.git
|
jandelgado/JLed @ ^4.15.0
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <WebSerial.h>
|
#include <WebSerial.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
#include "CG_RadSens.h"
|
#include <jled.h>
|
||||||
|
|
||||||
#define WIFI_SSID "wf-home"
|
#define WIFI_SSID "wf-home"
|
||||||
#define WIFI_PASSWORD "0ndthnrf"
|
#define WIFI_PASSWORD "0ndthnrf"
|
||||||
@@ -63,12 +63,14 @@ unsigned long stled;
|
|||||||
ESP8266WiFiMulti wifiMulti;
|
ESP8266WiFiMulti wifiMulti;
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
CG_RadSens radSens(RS_DEFAULT_I2C_ADDRESS);
|
|
||||||
bool rsOk;
|
bool rsOk;
|
||||||
float dynval; // Переменная для динамического значения интенсивности
|
float dynval; // Переменная для динамического значения интенсивности
|
||||||
float statval; // Переменная для статического значения интенсивности
|
float statval; // Переменная для статического значения интенсивности
|
||||||
uint32_t impval; // Переменная для кол-ва импульсов
|
uint32_t impval; // Переменная для кол-ва импульсов
|
||||||
|
|
||||||
|
auto bLed = JLed(LED_MQ);
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
@@ -115,7 +117,7 @@ void setup()
|
|||||||
|
|
||||||
|
|
||||||
pinMode(LED_WF, OUTPUT);
|
pinMode(LED_WF, OUTPUT);
|
||||||
pinMode(LED_MQ, OUTPUT);
|
//pinMode(LED_MQ, OUTPUT);
|
||||||
pinMode(LED_WRK, OUTPUT);
|
pinMode(LED_WRK, OUTPUT);
|
||||||
pinMode(LAMP_OUT, OUTPUT);
|
pinMode(LAMP_OUT, OUTPUT);
|
||||||
//pinMode(3, FUNCTION_3);
|
//pinMode(3, FUNCTION_3);
|
||||||
@@ -124,7 +126,7 @@ void setup()
|
|||||||
pinMode(PIN_MOVE, INPUT);
|
pinMode(PIN_MOVE, INPUT);
|
||||||
|
|
||||||
digitalWrite(LED_WF, LOW);
|
digitalWrite(LED_WF, LOW);
|
||||||
digitalWrite(LED_MQ, HIGH);
|
//digitalWrite(LED_MQ, HIGH);
|
||||||
digitalWrite(LED_WRK, LOW);
|
digitalWrite(LED_WRK, LOW);
|
||||||
|
|
||||||
EEPROM.begin(20);
|
EEPROM.begin(20);
|
||||||
@@ -155,13 +157,13 @@ void setup()
|
|||||||
server.begin();
|
server.begin();
|
||||||
//Wire.begin();
|
//Wire.begin();
|
||||||
//rsOk = radSens.init();
|
//rsOk = radSens.init();
|
||||||
radSens.setSensitivity(105);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
char v[6];
|
char v[6];
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
|
bLed.Update();
|
||||||
static unsigned long cRunADC = millis();
|
static unsigned long cRunADC = millis();
|
||||||
|
|
||||||
if(digitalRead(PIN_MOVE) > 0){
|
if(digitalRead(PIN_MOVE) > 0){
|
||||||
@@ -312,7 +314,8 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
mqttClient.subscribe(TOPIC"lightlev", 1);
|
mqttClient.subscribe(TOPIC"lightlev", 1);
|
||||||
|
|
||||||
//analogWrite(LED_MQ, 1023);
|
//analogWrite(LED_MQ, 1023);
|
||||||
digitalWrite(LED_MQ, LOW);
|
bLed.Breathe(2000).DelayAfter(1000).Forever();
|
||||||
|
//digitalWrite(LED_MQ, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
||||||
@@ -322,7 +325,8 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
mqttReconnectTimer.once(2, connectToMqtt);
|
mqttReconnectTimer.once(2, connectToMqtt);
|
||||||
}
|
}
|
||||||
//analogWrite(LED_MQ, 0);
|
//analogWrite(LED_MQ, 0);
|
||||||
digitalWrite(LED_MQ, HIGH);
|
bLed.Off();
|
||||||
|
//digitalWrite(LED_MQ, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
|
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ unsigned long cRun;
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
Ticker mqttReconnectTimer;
|
Ticker mqttReconnectTimer;
|
||||||
|
|||||||
5
KorMYS/.gitignore
vendored
5
KorMYS/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
10
KorMYS/.vscode/extensions.json
vendored
10
KorMYS/.vscode/extensions.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:uno]
|
|
||||||
platform = atmelavr
|
|
||||||
board = uno
|
|
||||||
framework = arduino
|
|
||||||
lib_deps =
|
|
||||||
featherfly/SoftwareSerial @ ^1.0
|
|
||||||
robtillaart/RunningMedian @ ^0.3.3
|
|
||||||
monitor_speed = 115200
|
|
||||||
@@ -1,289 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#define MY_DEBUG
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_REPEATER_FEATURE
|
|
||||||
#if F_CPU == 8000000L
|
|
||||||
#define MY_BAUD_RATE 38400
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MY_TRANSPORT_WAIT_READY_MS 10000
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
// Inverses the behavior of leds
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN A3 // Error led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN A4 // the PCB, on board LED
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN A5 // Receive led pin
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
#include <SDS011.h>
|
|
||||||
#include <SoftwareSerial.h>
|
|
||||||
#include <RunningMedian.h>
|
|
||||||
|
|
||||||
unsigned long cRun;
|
|
||||||
int cSec, adc, move, oldmov, minLight, minLightDB, LightInt, timeDelay, curDelay, fadeTime;
|
|
||||||
uint8_t sdsPeriod;
|
|
||||||
bool lamp;
|
|
||||||
RunningMedian samples = RunningMedian(5 * sizeof(int));
|
|
||||||
|
|
||||||
//float avgL;
|
|
||||||
#define RX_PIN 2
|
|
||||||
#define TX_PIN 3
|
|
||||||
#define LAMP_OUT 5
|
|
||||||
#define PIN_MOVE 7
|
|
||||||
SoftwareSerial sSerial(RX_PIN, TX_PIN);
|
|
||||||
SDS011 sds;
|
|
||||||
|
|
||||||
MyMessage msgHum25(0, V_LEVEL);
|
|
||||||
MyMessage msgHum10(1, V_LEVEL);
|
|
||||||
MyMessage msgLightLev(2, V_LEVEL);
|
|
||||||
MyMessage msgLightLevSet(3, V_VAR1);
|
|
||||||
MyMessage msgMillis(3, V_VAR4);
|
|
||||||
MyMessage msgMove(4, V_TRIPPED);
|
|
||||||
MyMessage msgLamp(5, V_VAR1);
|
|
||||||
void sendData(MyMessage msg, int status);
|
|
||||||
void sendData(MyMessage msg, float status);
|
|
||||||
void sendData(MyMessage msg, bool status);
|
|
||||||
void SDS011workmode(byte mode, SoftwareSerial *ser);
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
sSerial.begin(9600);
|
|
||||||
//set_per(2, &sSerial);
|
|
||||||
//SDS011workmode(2, &sSerial);
|
|
||||||
sds.begin(&sSerial);
|
|
||||||
Serial.println("Begin");
|
|
||||||
//Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
|
|
||||||
//Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
|
|
||||||
//Serial.println(sds.setCustomWorkingPeriod(3).toString()); // sensor sends data every 3 minutes
|
|
||||||
//sds.setActiveReportingMode();
|
|
||||||
//sds.setCustomWorkingPeriod(1);
|
|
||||||
pinMode(PIN_MOVE, INPUT_PULLUP);
|
|
||||||
pinMode(LAMP_OUT, OUTPUT);
|
|
||||||
//digitalWrite(7, HIGH);
|
|
||||||
//saveState(6, 2);
|
|
||||||
minLight = (loadState(0) << 8) + loadState(1);
|
|
||||||
minLightDB = (loadState(2) << 8) + loadState(3);
|
|
||||||
LightInt = (loadState(4) << 8) + loadState(5);
|
|
||||||
sdsPeriod = loadState(6);
|
|
||||||
timeDelay = (loadState(8) << 8) + loadState(9);
|
|
||||||
fadeTime = (loadState(10) << 8) + loadState(11);
|
|
||||||
curDelay = -1;
|
|
||||||
Serial.print(F("Min Light "));Serial.println(minLight);
|
|
||||||
Serial.print(F("Min LightDB "));Serial.println(minLightDB);
|
|
||||||
Serial.print(F("LightInt "));Serial.println(LightInt);
|
|
||||||
Serial.print(F("SDS Period "));Serial.println(sdsPeriod);
|
|
||||||
Serial.print(F("Time Delay "));Serial.println(timeDelay);
|
|
||||||
SDS011workmode(sdsPeriod, &sSerial);
|
|
||||||
// if(minLight == 0) minLight = 5;
|
|
||||||
//adc = analogRead(A0);
|
|
||||||
oldmov = 0;
|
|
||||||
lamp = false;
|
|
||||||
cRun = millis();
|
|
||||||
cSec = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
sendSketchInfo("Koridor", "1.0");
|
|
||||||
present(0, S_DUST, "pm2.5");
|
|
||||||
present(1, S_DUST, "pm10");
|
|
||||||
present(2, S_LIGHT_LEVEL, "minLight");
|
|
||||||
present(3, S_CUSTOM, "minLightSet");
|
|
||||||
present(4, S_MOTION, "Move");
|
|
||||||
present(5, S_CUSTOM, "LampOut");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
float p25, p10;
|
|
||||||
//uint32_t curTime;
|
|
||||||
|
|
||||||
if(digitalRead(PIN_MOVE) > 0){
|
|
||||||
if(curDelay == -1) sendData(msgMove, true);
|
|
||||||
move = true;
|
|
||||||
curDelay = timeDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if(move != oldmov){
|
|
||||||
// oldmov = move;
|
|
||||||
// sendData(msgMove, move);
|
|
||||||
// //send(msgMove.set(move));
|
|
||||||
// }
|
|
||||||
adc = analogRead(A0);
|
|
||||||
samples.add(adc);
|
|
||||||
adc = samples.getMedian();
|
|
||||||
if ((adc <= minLight) && (move == 1)){
|
|
||||||
analogWrite(LAMP_OUT, LightInt);
|
|
||||||
if(lamp == false){
|
|
||||||
Serial.println("Lamp ON");
|
|
||||||
Serial.print("ADC: ");Serial.print(adc);
|
|
||||||
Serial.print(", Move: ");Serial.println(move);
|
|
||||||
sendData(msgLightLev, adc);
|
|
||||||
//send(msgLightLev.set(adc, 2));
|
|
||||||
wait(50);
|
|
||||||
sendData(msgLamp, true);
|
|
||||||
//send(msgLamp.set(true));
|
|
||||||
lamp = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if((adc > (minLight + minLightDB)) || (move == 0)){
|
|
||||||
analogWrite(LAMP_OUT, 0);
|
|
||||||
//curDelay = 2;
|
|
||||||
if(lamp == true){
|
|
||||||
Serial.println("Lamp OFF");
|
|
||||||
Serial.print("ADC: ");Serial.print(adc);
|
|
||||||
Serial.print(", Move: ");Serial.println(move);
|
|
||||||
sendData(msgLightLev, adc);
|
|
||||||
//send(msgLightLev.set(adc, 2));
|
|
||||||
wait(50);
|
|
||||||
sendData(msgLamp, false);
|
|
||||||
//send(msgLamp.set(false));
|
|
||||||
lamp = false;
|
|
||||||
//curTime = millis() + fadeTime * 1000 ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(cRun + 999 < millis()){
|
|
||||||
cRun = millis();
|
|
||||||
if(curDelay == 0) {
|
|
||||||
sendData(msgMove, false);
|
|
||||||
move = false;
|
|
||||||
curDelay = -1;
|
|
||||||
}
|
|
||||||
if(curDelay > 0) curDelay--;
|
|
||||||
//if(curDelay == 1) curTime = cRun + fadeTime * 1000;
|
|
||||||
int error = sds.read(&p25, &p10);
|
|
||||||
if (!error) {
|
|
||||||
// Serial.println(millis()/1000);
|
|
||||||
// Serial.println("P2.5: " + String(p25));
|
|
||||||
// Serial.println("P10: " + String(p10));
|
|
||||||
sendData(msgHum25, p25);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgHum10, p10);
|
|
||||||
}
|
|
||||||
if (++cSec > 19){
|
|
||||||
cSec = 0;
|
|
||||||
wait(100);
|
|
||||||
sendData(msgLightLev, adc);
|
|
||||||
wait(100);
|
|
||||||
uint32_t ms = millis() /1000;
|
|
||||||
send(msgMillis.set(ms));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*if(lamp && curTime > millis()){
|
|
||||||
uint8_t ll = int(LightInt - LightInt * (1 - curTime - millis() / float(fadeTime * 1000)));
|
|
||||||
analogWrite(LAMP_OUT, ll);
|
|
||||||
if(curTime - millis() < 10){
|
|
||||||
lamp = false;
|
|
||||||
analogWrite(LAMP_OUT, 0);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void receive(const MyMessage &message)
|
|
||||||
{
|
|
||||||
if((message.sensor == 3) && (message.type == V_VAR1)){
|
|
||||||
minLight = message.getInt();
|
|
||||||
saveState(0, (minLight>>8) & 0xFF);
|
|
||||||
saveState(1, minLight & 0xFF);
|
|
||||||
Serial.print("minLight:");
|
|
||||||
Serial.println(minLight);
|
|
||||||
}
|
|
||||||
if((message.sensor == 3) && (message.type == V_VAR2)){
|
|
||||||
minLightDB = message.getInt();
|
|
||||||
saveState(2, (minLightDB>>8) & 0xFF);
|
|
||||||
saveState(3, minLightDB & 0xFF);
|
|
||||||
Serial.print("LightDB:");
|
|
||||||
Serial.println(minLightDB);
|
|
||||||
}
|
|
||||||
if((message.sensor == 3) && (message.type == V_VAR3)){
|
|
||||||
LightInt = message.getInt();
|
|
||||||
saveState(4, (LightInt>>8) & 0xFF);
|
|
||||||
saveState(5, LightInt & 0xFF);
|
|
||||||
Serial.print("Light Int:");
|
|
||||||
if (lamp == true) analogWrite(6, LightInt);
|
|
||||||
Serial.println(LightInt);
|
|
||||||
}
|
|
||||||
if((message.sensor == 3) && (message.type == V_VAR5)){
|
|
||||||
sdsPeriod = message.getInt();
|
|
||||||
saveState(6, sdsPeriod);
|
|
||||||
SDS011workmode(sdsPeriod, &sSerial);
|
|
||||||
Serial.print("Sds period:");
|
|
||||||
Serial.println(sdsPeriod);
|
|
||||||
}
|
|
||||||
if((message.sensor == 5) && (message.type == V_VAR2)){
|
|
||||||
timeDelay = message.getInt();
|
|
||||||
saveState(8, (timeDelay>>8) & 0xFF);
|
|
||||||
saveState(9, timeDelay & 0xFF);
|
|
||||||
Serial.print("time period:");
|
|
||||||
Serial.println(timeDelay);
|
|
||||||
}
|
|
||||||
if((message.sensor == 5) && (message.type == V_VAR3)){
|
|
||||||
fadeTime = message.getInt();
|
|
||||||
saveState(10, (fadeTime>>8) & 0xFF);
|
|
||||||
saveState(11, fadeTime & 0xFF);
|
|
||||||
Serial.print("fade period:");
|
|
||||||
Serial.println(fadeTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////// sends work mode command to SDS011 //////////////////////
|
|
||||||
void SDS011workmode(byte mode, SoftwareSerial *ser)
|
|
||||||
{
|
|
||||||
byte cs = 7 + mode;
|
|
||||||
uint8_t sleep_command[] = {0xAA, 0xB4, 0x08, 0x01, mode, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, cs, 0xAB};
|
|
||||||
// ^^ 0 for continuous, 1-30 for 1-30 min delay between turns on. ^^ checksum: 07 for 0x00, 08 for 0x01 and so on
|
|
||||||
for (uint8_t i = 0; i < 19; i++) {
|
|
||||||
ser->write(sleep_command[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendData(MyMessage msg, bool status)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(status));
|
|
||||||
if(!send_data)
|
|
||||||
wait(1000, C_SET, msg.type);
|
|
||||||
if ((count == 3)&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = true; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void sendData(MyMessage msg, float status)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(status, 1));
|
|
||||||
if(!send_data)
|
|
||||||
wait(1000, C_SET, msg.type);
|
|
||||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void sendData(MyMessage msg, int status)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(status));
|
|
||||||
if(!send_data)
|
|
||||||
wait(1000, C_SET, msg.type);
|
|
||||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
#define TOPIC "home/"
|
#define TOPIC "home/"
|
||||||
|
|
||||||
#define LED_WF (12)
|
#define LED_WF (12)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include <Ticker.h>
|
#include <Ticker.h>
|
||||||
#include <AsyncMqttClient.h>
|
#include <AsyncMqttClient.h>
|
||||||
|
#include <jled.h>
|
||||||
|
|
||||||
//#include <Adafruit_BME280.h>
|
//#include <Adafruit_BME280.h>
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ uint16_t stat[4];
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
#define TOPIC "home/"
|
#define TOPIC "home/"
|
||||||
|
|
||||||
unsigned long crun;
|
unsigned long crun;
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ lib_deps =
|
|||||||
finitespace/BME280 @ ^3.0.0
|
finitespace/BME280 @ ^3.0.0
|
||||||
milesburton/DallasTemperature @ ^3.9.1
|
milesburton/DallasTemperature @ ^3.9.1
|
||||||
thomasfredericks/Bounce2 @ ^2.55
|
thomasfredericks/Bounce2 @ ^2.55
|
||||||
mathertel/LiquidCrystal_PCF8574 @ ^1.2.0
|
https://github.com/mathertel/LiquidCrystal_PCF8574.git
|
||||||
marvinroger/AsyncMqttClient @ ^0.8.2
|
marvinroger/AsyncMqttClient @ ^0.8.2
|
||||||
|
jandelgado/JLed @ ^4.15.0
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ LiquidCrystal_PCF8574 lcd(0x3F); // set the LCD address to 0x27 for a 16 chars a
|
|||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
|
|
||||||
Bounce butt = Bounce();
|
Bounce butt = Bounce();
|
||||||
|
auto gLed = JLed(GREEN);
|
||||||
|
|
||||||
float tempC;
|
float tempC;
|
||||||
char f[4];
|
char f[4];
|
||||||
@@ -116,14 +117,16 @@ void setup() {
|
|||||||
connectToWifi();
|
connectToWifi();
|
||||||
|
|
||||||
crun = millis();
|
crun = millis();
|
||||||
|
gLed.Breathe(2000).DelayAfter(1000).MaxBrightness(16).Forever();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
float tempT(NAN), humT(NAN), pressT(NAN);
|
float tempT(NAN), humT(NAN), pressT(NAN);
|
||||||
static int gint = 1;
|
// static int gint = 1;
|
||||||
static bool gdir = true;
|
// static bool gdir = true;
|
||||||
|
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
|
gLed.Update();
|
||||||
|
|
||||||
butt.update();
|
butt.update();
|
||||||
if (butt.rose()){
|
if (butt.rose()){
|
||||||
@@ -135,10 +138,10 @@ void loop() {
|
|||||||
crun = millis();
|
crun = millis();
|
||||||
minCount++;
|
minCount++;
|
||||||
|
|
||||||
if(gdir) gint += 25;
|
// if(gdir) gint += 25;
|
||||||
else gint -= 25;
|
// else gint -= 25;
|
||||||
if((gint > 499) || (gint < 2)) gdir = !gdir;
|
// if((gint > 499) || (gint < 2)) gdir = !gdir;
|
||||||
analogWrite(GREEN, gint);
|
// analogWrite(GREEN, gint);
|
||||||
|
|
||||||
adc = analogRead(A0);
|
adc = analogRead(A0);
|
||||||
mv = digitalRead(MOVE_S);
|
mv = digitalRead(MOVE_S);
|
||||||
|
|||||||
5
LightCtrlMyS/.gitignore
vendored
5
LightCtrlMyS/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
7
LightCtrlMyS/.vscode/extensions.json
vendored
7
LightCtrlMyS/.vscode/extensions.json
vendored
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:pro8MHzatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = pro8MHzatmega328
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps =
|
|
||||||
mysensors/MySensors@^2.3.2
|
|
||||||
thomasfredericks/Bounce2 @ ^2.55
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#define MY_DEBUG
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 100
|
|
||||||
#define BUTT1 2
|
|
||||||
#define BUTT2 3
|
|
||||||
#define TIME_SLEEP 5 //Minutes
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
|
|
||||||
int8_t buttWU = MY_WAKE_UP_BY_TIMER;
|
|
||||||
uint16_t workMins = 0;
|
|
||||||
uint32_t minRun;
|
|
||||||
|
|
||||||
void presentation();
|
|
||||||
void sendDataI(MyMessage msg, uint32_t status);
|
|
||||||
void sendDataF(MyMessage msg, float status);
|
|
||||||
|
|
||||||
MyMessage msgLamp1(0, V_STATUS);
|
|
||||||
MyMessage msgLamp2(1, V_STATUS);
|
|
||||||
MyMessage msgMillis(2, V_VAR1);
|
|
||||||
MyMessage msgVoltage(2, V_VAR2);
|
|
||||||
|
|
||||||
int BATTERY_SENSE_PIN = A0;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
analogReference(INTERNAL);
|
|
||||||
pinMode(BUTT1, INPUT_PULLUP);
|
|
||||||
pinMode(BUTT2, INPUT_PULLUP);
|
|
||||||
minRun = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
int sensorValue = analogRead(BATTERY_SENSE_PIN);
|
|
||||||
float v = sensorValue * 0.0039561775471698;
|
|
||||||
if(buttWU == digitalPinToInterrupt(BUTT1)){
|
|
||||||
sendDataI(msgLamp1, (uint8_t)1);
|
|
||||||
sleep(1000);
|
|
||||||
//wait(100);
|
|
||||||
//Serial.println(F("Pressed: 1"));
|
|
||||||
}
|
|
||||||
if(buttWU == digitalPinToInterrupt(BUTT2)){
|
|
||||||
sendDataI(msgLamp2, (uint8_t)1);
|
|
||||||
sleep(1000);
|
|
||||||
//wait(100);
|
|
||||||
//Serial.println(F("Pressed: 2"));
|
|
||||||
}
|
|
||||||
if(buttWU == MY_WAKE_UP_BY_TIMER){
|
|
||||||
sendDataF(msgVoltage, v);
|
|
||||||
sendDataI(msgMillis, minRun++ * TIME_SLEEP);
|
|
||||||
}
|
|
||||||
buttWU = sleep(digitalPinToInterrupt(BUTT1), FALLING, digitalPinToInterrupt(BUTT2), FALLING, TIME_SLEEP * 60000 - 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
sendSketchInfo("LampCtrl", "1.0");
|
|
||||||
present(0, S_BINARY, "Lamp1");
|
|
||||||
present(1, S_BINARY, "Lamp2");
|
|
||||||
present(2, S_CUSTOM, "MillisVoltage");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendDataI(MyMessage msg, uint32_t val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val), true);
|
|
||||||
if(!send_data)
|
|
||||||
wait(500, C_SET, msg.type);
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendDataF(MyMessage msg, float val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val, 2), true);
|
|
||||||
if(!send_data)
|
|
||||||
wait(500, C_SET, msg.type);
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -21,3 +21,4 @@ lib_deps =
|
|||||||
# RECOMMENDED
|
# RECOMMENDED
|
||||||
# Accept new functionality in a backwards compatible manner and patches
|
# Accept new functionality in a backwards compatible manner and patches
|
||||||
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
ottowinter/AsyncMqttClient-esphome @ ^0.8.6
|
||||||
|
https://github.com/RobTillaart/PCF8574.git
|
||||||
@@ -16,7 +16,7 @@ IPAddress subnet(255, 255, 255, 0);
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
#define TOPIC "home/kor/"
|
#define TOPIC "home/kor/"
|
||||||
|
|
||||||
AsyncMqttClient mqttClient;
|
AsyncMqttClient mqttClient;
|
||||||
@@ -85,18 +85,11 @@ void onMqttConnect(bool sessionPresent) {
|
|||||||
Serial.println("Connected to MQTT.");
|
Serial.println("Connected to MQTT.");
|
||||||
Serial.print("Session present: ");
|
Serial.print("Session present: ");
|
||||||
Serial.println(sessionPresent);
|
Serial.println(sessionPresent);
|
||||||
//uint16_t packetIdSub =
|
|
||||||
//mqttClient.subscribe(TOPIC"doortimeout_set", 1);
|
|
||||||
mqttClient.publish(TOPIC"locker_top", 1, false, tP ? "0" : "1");
|
mqttClient.publish(TOPIC"locker_top", 1, false, tP ? "0" : "1");
|
||||||
mqttClient.publish(TOPIC"locker_int", 1, false, iP ? "0" : "1");
|
mqttClient.publish(TOPIC"locker_int", 1, false, iP ? "0" : "1");
|
||||||
mqttClient.publish(TOPIC"locker_down", 1, false, dP ? "0" : "1");
|
mqttClient.publish(TOPIC"locker_down", 1, false, dP ? "0" : "1");
|
||||||
mqttClient.publish(TOPIC"locker_small", 1, false, sP ? "0" : "1");
|
mqttClient.publish(TOPIC"locker_small", 1, false, sP ? "0" : "1");
|
||||||
mqttClient.publish(TOPIC"door", 1, false, doorP ? "1" : "0");
|
mqttClient.publish(TOPIC"door", 1, false, doorP ? "1" : "0");
|
||||||
//mqttClient.publish(TOPIC"doorlocker", 1, false, sP || dP || iP || tP ? "1" : "0");
|
|
||||||
/*char v[7];
|
|
||||||
itoa(timeAlm, v, 10);
|
|
||||||
mqttClient.publish(TOPIC"doortimeout", 1, false, v);*/
|
|
||||||
//digitalWrite(L_WIFI2, LOW);
|
|
||||||
digitalWrite(L_MQTT, HIGH);
|
digitalWrite(L_MQTT, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,8 +100,6 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
|
|||||||
mqttReconnectTimer.once(2, connectToMqtt);
|
mqttReconnectTimer.once(2, connectToMqtt);
|
||||||
}
|
}
|
||||||
digitalWrite(L_MQTT, LOW);
|
digitalWrite(L_MQTT, LOW);
|
||||||
//if(WiFi.isConnected())
|
|
||||||
// digitalWrite(L_WIFI2, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
|
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
|
||||||
@@ -126,16 +117,6 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
/* if(strcmp(topic, TOPIC"doortimeout_set") == 0){
|
|
||||||
char v[7];
|
|
||||||
timeAlm = atoi(payload);
|
|
||||||
EEPROM.put(0, timeAlm);
|
|
||||||
EEPROM.commit();
|
|
||||||
itoa(timeAlm, v, 10);
|
|
||||||
mqttClient.publish(TOPIC"doortimeout", 0, false, v);
|
|
||||||
Serial.print("New Timeout: ");
|
|
||||||
Serial.println(timeAlm);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMqttPublish(uint16_t packetId) {
|
void onMqttPublish(uint16_t packetId) {
|
||||||
@@ -190,32 +171,10 @@ void setup() {
|
|||||||
mqttClient.setClientId("Door");
|
mqttClient.setClientId("Door");
|
||||||
|
|
||||||
Wire.begin(SCL, SDA);
|
Wire.begin(SCL, SDA);
|
||||||
// Serial.println("Begin Scan");
|
|
||||||
// for (byte i = 8; i < 120; i++)
|
|
||||||
// {
|
|
||||||
// Wire.beginTransmission (i);
|
|
||||||
// if (Wire.endTransmission () == 0)
|
|
||||||
// {
|
|
||||||
// Serial.print ("Found address: ");
|
|
||||||
// Serial.print (i, DEC);
|
|
||||||
// Serial.print (" (0x");
|
|
||||||
// Serial.print (i, HEX);
|
|
||||||
// Serial.println (")");
|
|
||||||
// delay (1); // maybe unneeded?
|
|
||||||
// } // end of good response
|
|
||||||
// } // end of for loop
|
|
||||||
// Serial.println("End Scan");
|
|
||||||
//Wire.beginTransmission(0x3F);
|
|
||||||
Wire.beginTransmission(0x20);
|
Wire.beginTransmission(0x20);
|
||||||
if(Wire.endTransmission() == 0) Serial.println("PCF Found");
|
if(Wire.endTransmission() == 0) Serial.println("PCF Found");
|
||||||
else Serial.println("PCF Not Found");
|
else Serial.println("PCF Not Found");
|
||||||
pcf.begin(SCL, SDA);
|
pcf.begin();
|
||||||
|
|
||||||
// pinMode(L_TOP, INPUT_PULLUP);
|
|
||||||
// pinMode(L_INT, INPUT_PULLUP);
|
|
||||||
// pinMode(L_DOWN, INPUT_PULLUP);
|
|
||||||
// pinMode(L_SMALL, INPUT_PULLUP);
|
|
||||||
// pinMode(DOOR, INPUT_PULLUP);
|
|
||||||
pinMode(L_WIFI, OUTPUT);
|
pinMode(L_WIFI, OUTPUT);
|
||||||
//pinMode(L_WIFI2, OUTPUT);
|
//pinMode(L_WIFI2, OUTPUT);
|
||||||
pinMode(L_MQTT, OUTPUT);
|
pinMode(L_MQTT, OUTPUT);
|
||||||
@@ -235,26 +194,13 @@ void setup() {
|
|||||||
dP = dC =(pcfreg >> L_DOWN) & 0x1;
|
dP = dC =(pcfreg >> L_DOWN) & 0x1;
|
||||||
sP = sC = (pcfreg >> L_SMALL) & 0x1;
|
sP = sC = (pcfreg >> L_SMALL) & 0x1;
|
||||||
doorP = door = (pcfreg >> DOOR) & 0x1;// tP = digitalRead(L_TOP);
|
doorP = door = (pcfreg >> DOOR) & 0x1;// tP = digitalRead(L_TOP);
|
||||||
// iP = digitalRead(L_INT);
|
|
||||||
// dP = digitalRead(L_DOWN);
|
|
||||||
// sP = digitalRead(L_SMALL);
|
|
||||||
// EEPROM.begin(16);
|
|
||||||
// EEPROM.get(0, timeAlm);
|
|
||||||
// timeOpen = 0;
|
|
||||||
// doorSent = lockSent = false;
|
|
||||||
Serial.println("Connect to WiFi");
|
Serial.println("Connect to WiFi");
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
Serial.println("Loop");
|
Serial.println("Loop");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// uint8_t tC = digitalRead(L_TOP);
|
|
||||||
// uint8_t iC = digitalRead(L_INT);
|
|
||||||
// uint8_t dC = digitalRead(L_DOWN);
|
|
||||||
// uint8_t sC = digitalRead(L_SMALL);
|
|
||||||
//char v[10];
|
|
||||||
msg.tick();
|
msg.tick();
|
||||||
//door = digitalRead(DOOR);
|
|
||||||
if(l_m && (l_run + 100) < millis()){
|
if(l_m && (l_run + 100) < millis()){
|
||||||
analogWrite(L_MSG, 0);
|
analogWrite(L_MSG, 0);
|
||||||
l_m = false;
|
l_m = false;
|
||||||
@@ -271,11 +217,6 @@ void loop() {
|
|||||||
dC = (pcfreg >> L_DOWN) & 0x1;
|
dC = (pcfreg >> L_DOWN) & 0x1;
|
||||||
sC = (pcfreg >> L_SMALL) & 0x1;
|
sC = (pcfreg >> L_SMALL) & 0x1;
|
||||||
door = (pcfreg >> DOOR) & 0x1;
|
door = (pcfreg >> DOOR) & 0x1;
|
||||||
// if(opcfreg != pcfreg){
|
|
||||||
// itoa(pcfreg, v, 2);
|
|
||||||
// mqttClient.publish(TOPIC"pcf", 1, false, v);
|
|
||||||
// opcfreg = pcfreg;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(tC != tP){
|
if(tC != tP){
|
||||||
Serial.println("Top Changed");
|
Serial.println("Top Changed");
|
||||||
@@ -310,61 +251,17 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nSec++;
|
nSec++;
|
||||||
// if(nSec % 10 == 0){
|
|
||||||
// Serial.println(pcfreg, 2);
|
|
||||||
// // char v[11];
|
|
||||||
// // itoa(pcfreg, v, 2);
|
|
||||||
// // if(mqttClient.connected())
|
|
||||||
// // mqttClient.publish("/home/test/pcfreg", 0, false, v);
|
|
||||||
// }
|
|
||||||
if(nSec > 99){
|
if(nSec > 99){
|
||||||
if(mqttClient.connected()){
|
if(mqttClient.connected()){
|
||||||
char v[11];
|
char v[11];
|
||||||
dtostrf(millis() / 60000.0, 7, 1, v);
|
dtostrf(millis() / 60000.0, 7, 1, v);
|
||||||
trim(v);
|
trim(v);
|
||||||
//ultoa(millis(), v, 10);
|
|
||||||
//analogWrite(L_MSG, 1);
|
|
||||||
//l_run = millis();
|
|
||||||
//l_m = true;
|
|
||||||
//r_led.start();
|
|
||||||
mqttClient.publish(TOPIC"doormin", 1, false, v);
|
mqttClient.publish(TOPIC"doormin", 1, false, v);
|
||||||
Serial.print("Millis: ");
|
Serial.print("Millis: ");
|
||||||
Serial.println(millis());
|
Serial.println(millis());
|
||||||
}
|
}
|
||||||
nSec = 0;
|
nSec = 0;
|
||||||
}
|
}
|
||||||
/* if((((tC == 0) && (iC == 0) && (dC == 0) && (sC == 0)) || (door == 0)) && ((timeOpen / 10) < timeAlm)){
|
|
||||||
timeOpen++;
|
|
||||||
if((timeOpen / 10) >= timeAlm){
|
|
||||||
if(mqttClient.connected()){
|
|
||||||
if (door == 0){ //Door to long time open
|
|
||||||
r_led.start();
|
|
||||||
mqttClient.publish(TOPIC"doorlong", 1, false, "1");
|
|
||||||
doorSent = true;
|
|
||||||
}
|
|
||||||
else{ //Not closed locker
|
|
||||||
r_led.start();
|
|
||||||
mqttClient.publish(TOPIC"doorlocker", 1, false, "0");
|
|
||||||
lockSent = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
timeOpen = 0;
|
|
||||||
if(doorSent == true){
|
|
||||||
doorSent = false;
|
|
||||||
if(mqttClient.connected())
|
|
||||||
r_led.start();
|
|
||||||
mqttClient.publish(TOPIC"doorlong", 1, false, "0");
|
|
||||||
}
|
|
||||||
if(lockSent == true){
|
|
||||||
lockSent = false;
|
|
||||||
if(mqttClient.connected())
|
|
||||||
r_led.start();
|
|
||||||
mqttClient.publish(TOPIC"doorlocker", 1, false, "1");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
MainDoorMyS/.gitignore
vendored
5
MainDoorMyS/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
10
MainDoorMyS/.vscode/extensions.json
vendored
10
MainDoorMyS/.vscode/extensions.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:pro16MHzatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = pro16MHzatmega328
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps =
|
|
||||||
MySensors @ ^2.3.2
|
|
||||||
|
|
||||||
;[env:pro8MHzatmega168]
|
|
||||||
;platform = atmelavr
|
|
||||||
;board = pro8MHzatmega168
|
|
||||||
;framework = arduino
|
|
||||||
;monitor_speed = 115200
|
|
||||||
;lib_deps =
|
|
||||||
; MySensors @ ^2.3.2
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#define MY_DEBUG
|
|
||||||
|
|
||||||
// Enable and select radio type attached
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_REPEATER_FEATURE
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#if F_CPU == 8000000L
|
|
||||||
#define MY_BAUD_RATE 38400
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 100
|
|
||||||
#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 2 // Error led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN 3 // the PCB, on board LED
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN 4 // Receive led pin
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
|
|
||||||
#define TOP_LOCK A0 // 7 - Green/White
|
|
||||||
#define INT_LOCK A1 // 2 - Green
|
|
||||||
#define DOWN_LOCK A3 // 6 - Blue/White
|
|
||||||
#define SMALL_LOCK A2 // 1 - Blue
|
|
||||||
#define DOOR A4 // 3 - Brown
|
|
||||||
// 4 - 5V - Orange
|
|
||||||
// 8 - GND - Orange/White Brown/White
|
|
||||||
#define TOP_LOCK_ID 0
|
|
||||||
#define INT_LOCK_ID 1
|
|
||||||
#define DOWN_LOCK_ID 2
|
|
||||||
#define SMALL_LOCK_ID 3
|
|
||||||
#define DOOR_ID 4
|
|
||||||
#define CUSTOM_ID 5
|
|
||||||
|
|
||||||
bool bpTop, bpInt, bpDown, bpSmall, bpDoor;
|
|
||||||
|
|
||||||
MyMessage msgTop(TOP_LOCK_ID, V_LOCK_STATUS);
|
|
||||||
MyMessage msgInt(INT_LOCK_ID, V_LOCK_STATUS);
|
|
||||||
MyMessage msgDown(DOWN_LOCK_ID, V_LOCK_STATUS);
|
|
||||||
MyMessage msgSmall(SMALL_LOCK_ID, V_LOCK_STATUS);
|
|
||||||
MyMessage msgDoor(DOOR_ID, V_LOCK_STATUS);
|
|
||||||
MyMessage msgCust(CUSTOM_ID, V_VAR1);
|
|
||||||
void sendData(MyMessage msg, bool status);
|
|
||||||
|
|
||||||
void before()
|
|
||||||
{
|
|
||||||
pinMode(TOP_LOCK, INPUT_PULLUP);
|
|
||||||
pinMode(INT_LOCK, INPUT_PULLUP);
|
|
||||||
pinMode(DOWN_LOCK, INPUT_PULLUP);
|
|
||||||
pinMode(SMALL_LOCK, INPUT_PULLUP);
|
|
||||||
pinMode(DOOR, INPUT_PULLUP);
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
// Send the sketch version information to the gateway and Controller
|
|
||||||
sendSketchInfo("Main Door", "1.0");
|
|
||||||
present(TOP_LOCK_ID, S_LOCK, "Top");
|
|
||||||
present(INT_LOCK_ID, S_LOCK, "Int");
|
|
||||||
present(DOWN_LOCK_ID, S_LOCK, "Down");
|
|
||||||
present(SMALL_LOCK_ID, S_LOCK, "Small");
|
|
||||||
present(DOOR_ID, S_LOCK, "Door");
|
|
||||||
present(CUSTOM_ID, S_CUSTOM);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
bpDoor = !digitalRead(DOOR);
|
|
||||||
bpTop = !digitalRead(TOP_LOCK);
|
|
||||||
bpInt = !digitalRead(INT_LOCK);
|
|
||||||
bpSmall = !digitalRead(SMALL_LOCK);
|
|
||||||
bpDown = !digitalRead(DOWN_LOCK);
|
|
||||||
sendData(msgDoor, bpDoor);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgTop, bpTop);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgInt, bpInt);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgDown, bpDown);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgSmall, bpSmall);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
static uint32_t cRun = millis();
|
|
||||||
bool bTop, bInt, bDown, bSmall, bDoor;
|
|
||||||
bTop = !digitalRead(TOP_LOCK);
|
|
||||||
bInt = !digitalRead(INT_LOCK);
|
|
||||||
bDown = !digitalRead(DOWN_LOCK);
|
|
||||||
bSmall = !digitalRead(SMALL_LOCK);
|
|
||||||
bDoor = !digitalRead(DOOR);
|
|
||||||
if(bTop != bpTop){
|
|
||||||
bpTop = bTop;
|
|
||||||
Serial.print(F("Top Lock-"));Serial.println(bTop);
|
|
||||||
sendData(msgTop, bTop);
|
|
||||||
}
|
|
||||||
if(bInt != bpInt){
|
|
||||||
bpInt = bInt;
|
|
||||||
Serial.print(F("Int Lock-"));Serial.println(bInt);
|
|
||||||
sendData(msgInt, bInt);
|
|
||||||
}
|
|
||||||
if(bDown != bpDown){
|
|
||||||
bpDown = bDown;
|
|
||||||
Serial.print(F("Down Lock-"));Serial.println(bDown);
|
|
||||||
sendData(msgDown, bDown);
|
|
||||||
}
|
|
||||||
if(bSmall != bpSmall){
|
|
||||||
bpSmall = bSmall;
|
|
||||||
Serial.print(F("Small Lock-"));Serial.println(bSmall);
|
|
||||||
sendData(msgSmall, bSmall);
|
|
||||||
}
|
|
||||||
if(bDoor != bpDoor){
|
|
||||||
bpDoor = bDoor;
|
|
||||||
Serial.print(F("Door-"));Serial.println(bDoor);
|
|
||||||
sendData(msgDoor, bDoor);
|
|
||||||
}
|
|
||||||
if((cRun + 29949) < millis()){
|
|
||||||
wait(50);
|
|
||||||
cRun = millis();
|
|
||||||
send(msgCust.set(cRun));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendData(MyMessage msg, bool status)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
Serial.print("Sending a message, try No."); // Выводим в монитор порта попытку отправки
|
|
||||||
Serial.println(count); // и её номер
|
|
||||||
send_data = send(msg.set(status));
|
|
||||||
if(!send_data)
|
|
||||||
wait(100, C_SET, msg.type);
|
|
||||||
if(send_data)
|
|
||||||
Serial.println("Message sent");
|
|
||||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
Serial.println("Send failed"); // Выводим сообщение "Отправка не удалась"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
5
MidRoomNLight/.gitignore
vendored
5
MidRoomNLight/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
7
MidRoomNLight/.vscode/extensions.json
vendored
7
MidRoomNLight/.vscode/extensions.json
vendored
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:pro8MHzatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = pro8MHzatmega328
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps = mysensors/MySensors@^2.3.2
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#define MY_DEBUG
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
|
|
||||||
|
|
||||||
// Enable and select radio type attached
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_REPEATER_FEATURE
|
|
||||||
#include <MySensors.h>
|
|
||||||
|
|
||||||
#define RELAY_PIN 3 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
|
|
||||||
|
|
||||||
//MyMessage msgLev(1, V_DIMMER);
|
|
||||||
uint16_t lightLevel;
|
|
||||||
bool lightOn = false;
|
|
||||||
MyMessage msgMillis(1, V_VAR1);
|
|
||||||
|
|
||||||
void before()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
pinMode(RELAY_PIN, OUTPUT);
|
|
||||||
lightLevel = loadState(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
// Send the sketch version information to the gateway and Controller
|
|
||||||
sendSketchInfo("Night Light", "2.1");
|
|
||||||
present(0, S_DIMMER, "Dimmer");
|
|
||||||
present(1, S_CUSTOM, "Service");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
static uint32_t cRun = millis();
|
|
||||||
if((cRun + 10000) <= millis()){
|
|
||||||
cRun = millis();
|
|
||||||
send(msgMillis.set(cRun));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void receive(const MyMessage &message)
|
|
||||||
{
|
|
||||||
switch(message.getType()){
|
|
||||||
case V_STATUS:
|
|
||||||
if(message.getBool() == true) {
|
|
||||||
analogWrite(RELAY_PIN, lightLevel);
|
|
||||||
lightOn = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
analogWrite(RELAY_PIN, 0);
|
|
||||||
lightOn = false;
|
|
||||||
}
|
|
||||||
Serial.print("Incoming change for sensor:");
|
|
||||||
Serial.print(message.getSensor());
|
|
||||||
Serial.print(", New status: ");
|
|
||||||
Serial.println(message.getBool());
|
|
||||||
break;
|
|
||||||
case V_PERCENTAGE:
|
|
||||||
uint16_t lev = message.getUInt();
|
|
||||||
if(lev > 100) lev = 100;
|
|
||||||
saveState(0, int(lev * 2.55));
|
|
||||||
lightLevel = int(lev * 2.55);
|
|
||||||
if(lightOn) analogWrite(RELAY_PIN, lightLevel);
|
|
||||||
Serial.print("Incoming change for dimmer:");
|
|
||||||
Serial.print(message.getSensor());
|
|
||||||
Serial.print(", New value: ");
|
|
||||||
Serial.println(message.getUInt());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -40,4 +40,5 @@ lib_deps =
|
|||||||
swicago/HeatPump @ ^1.0.0
|
swicago/HeatPump @ ^1.0.0
|
||||||
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
ottowinter/ESPAsyncWebServer-esphome @ ^2.1.0
|
||||||
ayushsharma82/WebSerial @ ^1.3.0
|
ayushsharma82/WebSerial @ ^1.3.0
|
||||||
|
heman/AsyncMqttClient-esphome @ ^2.1.0
|
||||||
; bblanchon/ArduinoJson @ ^6.18.0
|
; bblanchon/ArduinoJson @ ^6.18.0
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
unsigned long cRun = millis();
|
unsigned long cRun = millis();
|
||||||
bool _debugMode;
|
bool _debugMode;
|
||||||
|
|
||||||
|
|||||||
5
Rozetka/.gitignore
vendored
5
Rozetka/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
10
Rozetka/.vscode/extensions.json
vendored
10
Rozetka/.vscode/extensions.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:pro8MHzatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = pro8MHzatmega328
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps =
|
|
||||||
mysensors/MySensors@^2.3.2
|
|
||||||
thomasfredericks/Bounce2 @ ^2.55
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#define MY_DEBUG
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_REPEATER_FEATURE
|
|
||||||
|
|
||||||
#define SOCK1 2
|
|
||||||
#define SOCK2 3
|
|
||||||
#define RELAY1 A0
|
|
||||||
#define RELAY2 A1
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN (4) // Error led pin
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN (5) // Receive led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN (6) // the PCB, on board LED
|
|
||||||
#define BUTT1 8
|
|
||||||
#define BUTT2 7
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
#include <Bounce2.h>
|
|
||||||
|
|
||||||
|
|
||||||
// #undef MY_NODE_ID
|
|
||||||
// #define MY_NODE_ID 14
|
|
||||||
|
|
||||||
bool stat1, stat2, Ack;
|
|
||||||
void presentation();
|
|
||||||
void sendData(MyMessage msg, bool status);
|
|
||||||
void sendData(MyMessage msg, uint32_t status);
|
|
||||||
void receive(const MyMessage &message);
|
|
||||||
|
|
||||||
MyMessage msgMillis(2, V_VAR1);
|
|
||||||
MyMessage msgSock1s(0, V_STATUS);
|
|
||||||
MyMessage msgSock2s(1, V_STATUS);
|
|
||||||
MyMessage msgSock1(2, V_VAR2);
|
|
||||||
MyMessage msgSock2(2, V_VAR3);
|
|
||||||
|
|
||||||
Bounce butt1 = Bounce(), butt2 = Bounce();
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
pinMode(SOCK1, OUTPUT);
|
|
||||||
pinMode(SOCK2, OUTPUT);
|
|
||||||
pinMode(RELAY1, OUTPUT);
|
|
||||||
pinMode(RELAY2, OUTPUT);
|
|
||||||
butt1.attach(BUTT1, INPUT_PULLUP);
|
|
||||||
butt2.attach(BUTT2, INPUT_PULLUP);
|
|
||||||
butt1.interval(25);
|
|
||||||
butt2.interval(25);
|
|
||||||
stat1 = loadState(0);
|
|
||||||
digitalWrite(SOCK1, stat1);
|
|
||||||
digitalWrite(RELAY1, !stat1);
|
|
||||||
stat2 = loadState(1);
|
|
||||||
digitalWrite(SOCK2, stat2);
|
|
||||||
digitalWrite(RELAY2, !stat2);
|
|
||||||
sendData(msgSock1s, !stat1);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgSock2s, !stat2);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgSock1, !stat1);
|
|
||||||
wait(100);
|
|
||||||
sendData(msgSock2, !stat2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
static uint32_t cRun = millis() - 60000;
|
|
||||||
butt1.update();
|
|
||||||
butt2.update();
|
|
||||||
if(butt1.fell()){
|
|
||||||
stat1 = !stat1;
|
|
||||||
digitalWrite(SOCK1, stat1);
|
|
||||||
digitalWrite(RELAY1, !stat1);
|
|
||||||
sendData(msgSock1s, !stat1);
|
|
||||||
sendData(msgSock1, !stat1);
|
|
||||||
saveState(0, stat1);
|
|
||||||
Serial.print(F("Change Sock1: ")); Serial.println(stat1);
|
|
||||||
}
|
|
||||||
if(butt2.fell()){
|
|
||||||
stat2 = !stat2;
|
|
||||||
digitalWrite(SOCK2, stat2);
|
|
||||||
digitalWrite(RELAY2, !stat2);
|
|
||||||
sendData(msgSock2s, !stat2);
|
|
||||||
sendData(msgSock2, !stat2);
|
|
||||||
saveState(1, stat2);
|
|
||||||
Serial.print(F("Change Sock2: ")); Serial.println(stat2);
|
|
||||||
}
|
|
||||||
if(stat1 != digitalRead(SOCK1)){
|
|
||||||
Serial.print(F("Curr Sock1: ")); Serial.println(digitalRead(SOCK1));
|
|
||||||
Serial.print(F("Change Sock1: ")); Serial.println(stat1);
|
|
||||||
digitalWrite(SOCK1, stat1);
|
|
||||||
digitalWrite(RELAY1, !stat1);
|
|
||||||
saveState(0, digitalRead(SOCK1));
|
|
||||||
sendData(msgSock1, !stat1);
|
|
||||||
}
|
|
||||||
if(stat2 != digitalRead(SOCK2)){
|
|
||||||
Serial.print(F("Curr Sock2: ")); Serial.println(digitalRead(SOCK2));
|
|
||||||
digitalWrite(SOCK2, stat2);
|
|
||||||
digitalWrite(RELAY2, !stat2);
|
|
||||||
saveState(1, digitalRead(SOCK2));
|
|
||||||
sendData(msgSock2, !stat2);
|
|
||||||
Serial.print(F("Change Sock2: ")); Serial.println(stat2);
|
|
||||||
}
|
|
||||||
if((cRun + 60000) <= millis()){
|
|
||||||
cRun = millis();
|
|
||||||
sendData(msgMillis, cRun);
|
|
||||||
//send(msgMillis.set(cRun));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void presentation()
|
|
||||||
{
|
|
||||||
sendSketchInfo("Rozetka", "1.0");
|
|
||||||
present(0, S_BINARY, "Socket1");
|
|
||||||
present(1, S_BINARY, "Socket2");
|
|
||||||
present(2, S_CUSTOM, "ESMillis");
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendData(MyMessage msg, bool status)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(status), true);
|
|
||||||
wait(1000, C_SET, msg.type);
|
|
||||||
if ((count == 3 )&&(send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendData(MyMessage msg, uint32_t val)
|
|
||||||
{
|
|
||||||
bool send_data = false;
|
|
||||||
uint8_t count = 0;
|
|
||||||
Ack = false;
|
|
||||||
//Serial.print(millis());
|
|
||||||
//Serial.println(" Send UINT32 Enter");
|
|
||||||
while(send_data == false){
|
|
||||||
count++;
|
|
||||||
send_data = send(msg.set(val), true);
|
|
||||||
wait(1000, C_SET, msg.type);
|
|
||||||
//Serial.print(millis());
|
|
||||||
//Serial.println(" Send UINT32");
|
|
||||||
if ((count == 3) && (send_data == 0)){ // Если сделано 3 попытки и нет подтверждения отправки
|
|
||||||
count = 0; // Обнуляем счётчик
|
|
||||||
send_data = 1; // Выходим из цикла
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if(Ack){
|
|
||||||
// Serial.print(millis());
|
|
||||||
// Serial.println(" Send UINT32 OK");
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
void receive(const MyMessage &message)
|
|
||||||
{
|
|
||||||
if(message.isAck()) {Ack = true; return;}
|
|
||||||
if(message.getType() != V_STATUS) return;
|
|
||||||
switch (message.sensor)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
stat1 = !message.getBool();
|
|
||||||
Serial.print(F("Recv1: ")); Serial.println(stat1);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
stat2 = !message.getBool();
|
|
||||||
Serial.print(F("Recv2: ")); Serial.println(stat2);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
const char* ssid = "wf-home";
|
const char* ssid = "wf-home";
|
||||||
const char* password = "0ndthnrf";
|
const char* password = "0ndthnrf";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
#define TOPIC "home/"
|
#define TOPIC "home/"
|
||||||
|
|
||||||
Bounce but1 = Bounce();
|
Bounce but1 = Bounce();
|
||||||
|
|||||||
5
SerialGateWayMyS/.gitignore
vendored
5
SerialGateWayMyS/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
7
SerialGateWayMyS/.vscode/extensions.json
vendored
7
SerialGateWayMyS/.vscode/extensions.json
vendored
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
28
SerialGateWayMyS/.vscode/tasks.json
vendored
28
SerialGateWayMyS/.vscode/tasks.json
vendored
@@ -1,28 +0,0 @@
|
|||||||
{
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "cppbuild",
|
|
||||||
"label": "C/C++: avr-gcc.exe build active file",
|
|
||||||
"command": "C:/Users/lexa-/.platformio/packages/toolchain-atmelavr@1.50400.190710/bin/avr-gcc.exe",
|
|
||||||
"args": [
|
|
||||||
"-g",
|
|
||||||
"${file}",
|
|
||||||
"-o",
|
|
||||||
"${fileDirname}\\${fileBasenameNoExtension}.exe",
|
|
||||||
"-mmcu=atmega328p"
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "C:/Users/lexa-/.platformio/packages/toolchain-atmelavr@1.50400.190710/bin"
|
|
||||||
},
|
|
||||||
"problemMatcher": [
|
|
||||||
"$gcc"
|
|
||||||
],
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
},
|
|
||||||
"detail": "Generated task by Debugger"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": "2.0.0"
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
; PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:nanoatmega328]
|
|
||||||
platform = atmelavr
|
|
||||||
board = nanoatmega328
|
|
||||||
;board = uno
|
|
||||||
framework = arduino
|
|
||||||
monitor_speed = 115200
|
|
||||||
lib_deps = featherfly/SoftwareSerial @ ^1.0
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#define MY_DEBUG
|
|
||||||
//#define MY_DEBUG_VERBOSE_RF24
|
|
||||||
#define MY_RADIO_RF24
|
|
||||||
#define MY_RF24_PA_LEVEL RF24_PA_MAX
|
|
||||||
#define MY_GATEWAY_SERIAL
|
|
||||||
#define MY_RF24_CHANNEL (105)
|
|
||||||
#define MY_RX_MESSAGE_BUFFER_FEATURE
|
|
||||||
#define MY_RF24_IRQ_PIN (3)
|
|
||||||
// Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
|
|
||||||
#if F_CPU == 8000000L
|
|
||||||
#define MY_BAUD_RATE 38400
|
|
||||||
#endif
|
|
||||||
// Set blinking period
|
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
|
||||||
// Inverses the behavior of leds
|
|
||||||
//#define MY_WITH_LEDS_BLINKING_INVERSE
|
|
||||||
// Flash leds on rx/tx/err
|
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 6 // Error led pin
|
|
||||||
#define MY_DEFAULT_RX_LED_PIN 4 // Receive led pin
|
|
||||||
#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED
|
|
||||||
|
|
||||||
#include <MySensors.h>
|
|
||||||
|
|
||||||
unsigned long cRun;
|
|
||||||
int cSec;
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.println("Begin");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PlatformIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
#define WIFI_PASSWORD "0ndthnrf"
|
#define WIFI_PASSWORD "0ndthnrf"
|
||||||
#define MY_HOSTNAME "ESP8266_GW"
|
#define MY_HOSTNAME "ESP8266_GW"
|
||||||
//#define MQTT_SERV "192.168.1.250"
|
//#define MQTT_SERV "192.168.1.250"
|
||||||
#define MQTT_SERV "192.168.1.111"
|
#define MQTT_SERV "192.168.1.10"
|
||||||
#define TOPIC "home/"
|
#define TOPIC "home/"
|
||||||
|
|
||||||
#define MAX_PAGE (4)
|
#define MAX_PAGE (4)
|
||||||
@@ -71,7 +71,7 @@ WiFiEventHandler wifiConnectHandler;
|
|||||||
WiFiEventHandler wifiDisconnectHandler;
|
WiFiEventHandler wifiDisconnectHandler;
|
||||||
Ticker wifiReconnectTimer;
|
Ticker wifiReconnectTimer;
|
||||||
//const char* mqtt_server = "192.168.1.250";
|
//const char* mqtt_server = "192.168.1.250";
|
||||||
const char* mqtt_server = "192.168.1.111";
|
const char* mqtt_server = "192.168.1.10";
|
||||||
char v[12];
|
char v[12];
|
||||||
|
|
||||||
struct contacts
|
struct contacts
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ void setup()
|
|||||||
lcd.setBacklight(255);
|
lcd.setBacklight(255);
|
||||||
lcd.setCursor(0, 0);
|
lcd.setCursor(0, 0);
|
||||||
lcd.print(F("Booting"));
|
lcd.print(F("Booting"));
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.hostname("VT_ESP");
|
WiFi.hostname("VT_ESP");
|
||||||
// WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
// WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
// if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
// if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||||
|
|||||||
5
esp8266-KUH/.gitignore
vendored
5
esp8266-KUH/.gitignore
vendored
@@ -1,5 +0,0 @@
|
|||||||
.pio
|
|
||||||
.vscode/.browse.c_cpp.db*
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
.vscode/launch.json
|
|
||||||
.vscode/ipch
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
# Continuous Integration (CI) is the practice, in software
|
|
||||||
# engineering, of merging all developer working copies with a shared mainline
|
|
||||||
# several times a day < https://docs.platformio.org/page/ci/index.html >
|
|
||||||
#
|
|
||||||
# Documentation:
|
|
||||||
#
|
|
||||||
# * Travis CI Embedded Builds with PlatformIO
|
|
||||||
# < https://docs.travis-ci.com/user/integration/platformio/ >
|
|
||||||
#
|
|
||||||
# * PlatformIO integration with Travis CI
|
|
||||||
# < https://docs.platformio.org/page/ci/travis.html >
|
|
||||||
#
|
|
||||||
# * User Guide for `platformio ci` command
|
|
||||||
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Please choose one of the following templates (proposed below) and uncomment
|
|
||||||
# it (remove "# " before each line) or use own configuration according to the
|
|
||||||
# Travis CI documentation (see above).
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Template #1: General project. Test it using existing `platformio.ini`.
|
|
||||||
#
|
|
||||||
|
|
||||||
# language: python
|
|
||||||
# python:
|
|
||||||
# - "2.7"
|
|
||||||
#
|
|
||||||
# sudo: false
|
|
||||||
# cache:
|
|
||||||
# directories:
|
|
||||||
# - "~/.platformio"
|
|
||||||
#
|
|
||||||
# install:
|
|
||||||
# - pip install -U platformio
|
|
||||||
# - platformio update
|
|
||||||
#
|
|
||||||
# script:
|
|
||||||
# - platformio run
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Template #2: The project is intended to be used as a library with examples.
|
|
||||||
#
|
|
||||||
|
|
||||||
# language: python
|
|
||||||
# python:
|
|
||||||
# - "2.7"
|
|
||||||
#
|
|
||||||
# sudo: false
|
|
||||||
# cache:
|
|
||||||
# directories:
|
|
||||||
# - "~/.platformio"
|
|
||||||
#
|
|
||||||
# env:
|
|
||||||
# - PLATFORMIO_CI_SRC=path/to/test/file.c
|
|
||||||
# - PLATFORMIO_CI_SRC=examples/file.ino
|
|
||||||
# - PLATFORMIO_CI_SRC=path/to/test/directory
|
|
||||||
#
|
|
||||||
# install:
|
|
||||||
# - pip install -U platformio
|
|
||||||
# - platformio update
|
|
||||||
#
|
|
||||||
# script:
|
|
||||||
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
|
|
||||||
7
esp8266-KUH/.vscode/extensions.json
vendored
7
esp8266-KUH/.vscode/extensions.json
vendored
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
|
||||||
// for the documentation about the extensions.json format
|
|
||||||
"recommendations": [
|
|
||||||
"platformio.platformio-ide"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project header files.
|
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
|
||||||
to be shared between several project source files. You request the use of a
|
|
||||||
header file in your project source file (C, C++, etc) located in `src` folder
|
|
||||||
by including it, with the C preprocessing directive `#include'.
|
|
||||||
|
|
||||||
```src/main.c
|
|
||||||
|
|
||||||
#include "header.h"
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Including a header file produces the same results as copying the header file
|
|
||||||
into each source file that needs it. Such copying would be time-consuming
|
|
||||||
and error-prone. With a header file, the related declarations appear
|
|
||||||
in only one place. If they need to be changed, they can be changed in one
|
|
||||||
place, and programs that include the header file will automatically use the
|
|
||||||
new version when next recompiled. The header file eliminates the labor of
|
|
||||||
finding and changing all the copies as well as the risk that a failure to
|
|
||||||
find one copy will result in inconsistencies within a program.
|
|
||||||
|
|
||||||
In C, the usual convention is to give header files names that end with `.h'.
|
|
||||||
It is most portable to use only letters, digits, dashes, and underscores in
|
|
||||||
header file names, and at most one dot.
|
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
|
||||||
|
|
||||||
* Include Syntax
|
|
||||||
* Include Operation
|
|
||||||
* Once-Only Headers
|
|
||||||
* Computed Includes
|
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include <SPI.h>
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <WiFiClient.h>
|
|
||||||
//#include <ESP8266WebServer.h>
|
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <ArduinoOTA.h>
|
|
||||||
#include <PubSubClient.h>
|
|
||||||
#include <BME280I2C.h>
|
|
||||||
//#include <ArduinoJson.h>
|
|
||||||
|
|
||||||
#include <EEPROM.h>
|
|
||||||
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <pcf8574_esp.h>
|
|
||||||
#include <LiquidCrystal_PCF8574.h>
|
|
||||||
|
|
||||||
#include <DallasTemperature.h>
|
|
||||||
|
|
||||||
#include <Bounce2.h>
|
|
||||||
|
|
||||||
#define ONE_WIRE_BUS D4
|
|
||||||
|
|
||||||
union uFloat {
|
|
||||||
byte b[4];
|
|
||||||
float f;
|
|
||||||
int i;
|
|
||||||
} wcH, wcC, ls, ld;
|
|
||||||
|
|
||||||
void wCycle();
|
|
||||||
void showLCD();
|
|
||||||
void getTemp();
|
|
||||||
void initLCD();
|
|
||||||
void initWiFi();
|
|
||||||
void initTemp();
|
|
||||||
//void readEEPROM();
|
|
||||||
void readDI();
|
|
||||||
void movSens();
|
|
||||||
void callback(String topic, byte* message, unsigned int length);
|
|
||||||
void reconnect();
|
|
||||||
void handleData();
|
|
||||||
//void writeEEPROM(const char tip[2], uFloat val);
|
|
||||||
void publishSec();
|
|
||||||
void publishMin();
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
|
||||||
|
|
||||||
The source code of each library should be placed in a an own separate directory
|
|
||||||
("lib/your_library_name/[here are source files]").
|
|
||||||
|
|
||||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
|
||||||
|
|
||||||
|--lib
|
|
||||||
| |
|
|
||||||
| |--Bar
|
|
||||||
| | |--docs
|
|
||||||
| | |--examples
|
|
||||||
| | |--src
|
|
||||||
| | |- Bar.c
|
|
||||||
| | |- Bar.h
|
|
||||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
|
||||||
| |
|
|
||||||
| |--Foo
|
|
||||||
| | |- Foo.c
|
|
||||||
| | |- Foo.h
|
|
||||||
| |
|
|
||||||
| |- README --> THIS FILE
|
|
||||||
|
|
|
||||||
|- platformio.ini
|
|
||||||
|--src
|
|
||||||
|- main.c
|
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
|
||||||
```
|
|
||||||
#include <Foo.h>
|
|
||||||
#include <Bar.h>
|
|
||||||
|
|
||||||
int main (void)
|
|
||||||
{
|
|
||||||
...
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
PlatformIO Library Dependency Finder will find automatically dependent
|
|
||||||
libraries scanning project source files.
|
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
;PlatformIO Project Configuration File
|
|
||||||
;
|
|
||||||
; Build options: build flags, source filter
|
|
||||||
; Upload options: custom upload port, speed and extra flags
|
|
||||||
; Library options: dependencies, extra library storages
|
|
||||||
; Advanced options: extra scripting
|
|
||||||
;
|
|
||||||
; Please visit documentation for the other options and examples
|
|
||||||
; https://docs.platformio.org/page/projectconf.html
|
|
||||||
|
|
||||||
[env:nodemcuv2]
|
|
||||||
platform = espressif8266
|
|
||||||
board = nodemcuv2
|
|
||||||
framework = arduino
|
|
||||||
upload_protocol = espota
|
|
||||||
upload_port = 192.168.1.6
|
|
||||||
|
|
||||||
@@ -1,780 +0,0 @@
|
|||||||
#include "main.h"
|
|
||||||
|
|
||||||
const char* host = "esp8266";
|
|
||||||
const char* ssid = "wf-home";
|
|
||||||
const char* password = "0ndthnrf";
|
|
||||||
|
|
||||||
const char* mqtt_server = "192.168.1.250";
|
|
||||||
|
|
||||||
//ESP8266WebServer server(80);
|
|
||||||
|
|
||||||
// инициализируем espClient:
|
|
||||||
WiFiClient espClient;
|
|
||||||
PubSubClient client(espClient);
|
|
||||||
|
|
||||||
LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
|
|
||||||
|
|
||||||
int nDevs;
|
|
||||||
DeviceAddress da[4] = {
|
|
||||||
{0x28, 0xFF, 0x75, 0x3f, 0x93, 0x16, 0x04, 0xce},
|
|
||||||
{0x28, 0x85, 0xcd, 0x1b, 0x05, 0x00, 0x00, 0x48},
|
|
||||||
{0x28, 0xff, 0x79, 0x41, 0x88, 0x16, 0x03, 0x5a},
|
|
||||||
{0x28, 0x20, 0xbe, 0x1b, 0x05, 0x00, 0x00, 0xdc}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
|
|
||||||
OneWire oneWire(ONE_WIRE_BUS);
|
|
||||||
|
|
||||||
// Pass our oneWire reference to Dallas Temperature.
|
|
||||||
DallasTemperature sensors(&oneWire);
|
|
||||||
|
|
||||||
float temp1, tHolTop, tHolDown, tMoroz;
|
|
||||||
//float hum;
|
|
||||||
float hic;
|
|
||||||
//float temp2;
|
|
||||||
//float pres, bmpTemp;
|
|
||||||
|
|
||||||
int old_wcC, old_wcH;
|
|
||||||
int adc;
|
|
||||||
float temp[4];
|
|
||||||
|
|
||||||
|
|
||||||
const int led = LED_BUILTIN;
|
|
||||||
const int HOT_SENS = D5;
|
|
||||||
const int COLD_SENS = D6;
|
|
||||||
const int LED_STRIPE = D7;
|
|
||||||
const int LCD_MODE = D8;
|
|
||||||
const int RSET_FLOOD = D4;
|
|
||||||
|
|
||||||
unsigned long oldRun = millis();
|
|
||||||
|
|
||||||
bool Flood = false;
|
|
||||||
|
|
||||||
TwoWire testWire;
|
|
||||||
PCF857x pcf8574(0x38, &testWire);
|
|
||||||
|
|
||||||
/*const int MB_LED = 0;
|
|
||||||
const int VLZEM_LED = 1;
|
|
||||||
const int BOX_LED = 2;
|
|
||||||
const int FLOOD_LED = 3; */
|
|
||||||
|
|
||||||
|
|
||||||
//Bounce modeLCD_dbnc = Bounce();
|
|
||||||
//Bounce hot_dbnc = Bounce();
|
|
||||||
//Bounce cold_dbnc = Bounce();
|
|
||||||
//Bounce rset_dbnc = Bounce();
|
|
||||||
|
|
||||||
bool bMLCD;
|
|
||||||
short sLCDPage;
|
|
||||||
|
|
||||||
BME280I2C::Settings settings(
|
|
||||||
BME280::OSR_X1,
|
|
||||||
BME280::OSR_X2,
|
|
||||||
BME280::OSR_X16,
|
|
||||||
BME280::Mode_Normal,
|
|
||||||
BME280::StandbyTime_1000ms,
|
|
||||||
BME280::Filter_16,
|
|
||||||
BME280::SpiEnable_False,
|
|
||||||
BME280I2C::I2CAddr_0x76 // I2C address. I2C specific.
|
|
||||||
);
|
|
||||||
BME280I2C bme(settings); // Default : forced mode, standby time = 1000 ms
|
|
||||||
// Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off,
|
|
||||||
float temp2(NAN), hum(NAN), pres(NAN);
|
|
||||||
|
|
||||||
bool movSensor = 0;
|
|
||||||
bool MS = 0;
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(115200);
|
|
||||||
Serial.println("Init LCD");
|
|
||||||
initLCD();
|
|
||||||
delay(500);
|
|
||||||
Serial.println("Init BME280");
|
|
||||||
int nt = 0;
|
|
||||||
while (!bme.begin()) {
|
|
||||||
Serial.println("Could not find a valid BMe280 sensor, check wiring!");
|
|
||||||
delay(1000);
|
|
||||||
nt++;
|
|
||||||
if (nt > 10) break;
|
|
||||||
}
|
|
||||||
delay(500);
|
|
||||||
Serial.println("Init Temperature");
|
|
||||||
initTemp();
|
|
||||||
bme.read(pres, temp2, hum, BME280::TempUnit_Celsius, BME280::PresUnit_torr);
|
|
||||||
|
|
||||||
pinMode(led, OUTPUT);
|
|
||||||
digitalWrite(led, 1);
|
|
||||||
pinMode(HOT_SENS, INPUT_PULLUP);
|
|
||||||
pinMode(COLD_SENS, INPUT_PULLUP);
|
|
||||||
pinMode(LED_STRIPE, OUTPUT);
|
|
||||||
pinMode(LCD_MODE, INPUT_PULLUP);
|
|
||||||
pinMode(D4, INPUT_PULLUP);
|
|
||||||
|
|
||||||
//hot_dbnc.attach(HOT_SENS);
|
|
||||||
//hot_dbnc.interval(5); // interval in ms
|
|
||||||
//cold_dbnc.attach(COLD_SENS);
|
|
||||||
//cold_dbnc.interval(5); // interval in ms
|
|
||||||
/*modeLCD_dbnc.attach(LCD_MODE);
|
|
||||||
modeLCD_dbnc.interval(5); // interval in ms
|
|
||||||
rset_dbnc.attach(RSET_FLOOD);
|
|
||||||
rset_dbnc.interval(5); // interval in ms*/
|
|
||||||
|
|
||||||
|
|
||||||
EEPROM.begin(16);
|
|
||||||
//readEEPROM();
|
|
||||||
//Serial.print("Hot water: ");
|
|
||||||
//Serial.print(float(wcH.i) / 100.0);
|
|
||||||
//Serial.print("Cold water: ");
|
|
||||||
//Serial.println(float(wcC.i) / 100.0);
|
|
||||||
//Serial.print("LS Set: ");
|
|
||||||
//Serial.println(ls.i);
|
|
||||||
//Serial.print("LS DB: ");
|
|
||||||
//Serial.println(ld.i);
|
|
||||||
ls.i = 250;
|
|
||||||
ld.i = 50;
|
|
||||||
//old_wcC = wcC.i;
|
|
||||||
//old_wcH = wcH.i;
|
|
||||||
|
|
||||||
testWire.begin();//5, 4);
|
|
||||||
testWire.setClock(100000L);
|
|
||||||
pcf8574.begin();
|
|
||||||
bMLCD = false;
|
|
||||||
readDI();
|
|
||||||
sLCDPage = 0;
|
|
||||||
initWiFi();
|
|
||||||
client.setServer(mqtt_server, 1883);
|
|
||||||
client.setCallback(callback);
|
|
||||||
|
|
||||||
ArduinoOTA.onStart([]() {
|
|
||||||
Serial.println("Start"); // "Начало OTA-апдейта"
|
|
||||||
});
|
|
||||||
ArduinoOTA.onEnd([]() {
|
|
||||||
Serial.println("\nEnd"); // "Завершение OTA-апдейта"
|
|
||||||
});
|
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
||||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
|
||||||
});
|
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
|
||||||
Serial.printf("Error[%u]: ", error);
|
|
||||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
|
||||||
// "Ошибка при аутентификации"
|
|
||||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
|
||||||
// "Ошибка при начале OTA-апдейта"
|
|
||||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
|
||||||
// "Ошибка при подключении"
|
|
||||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
|
||||||
// "Ошибка при получении данных"
|
|
||||||
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
|
||||||
// "Ошибка при завершении OTA-апдейта"
|
|
||||||
});
|
|
||||||
ArduinoOTA.begin();
|
|
||||||
} // setup()
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
unsigned long curTime = millis();
|
|
||||||
if ((curTime - oldRun) >= 10){
|
|
||||||
wCycle();
|
|
||||||
oldRun = curTime;
|
|
||||||
}
|
|
||||||
//server.handleClient();
|
|
||||||
ArduinoOTA.handle();
|
|
||||||
//movSens();
|
|
||||||
}
|
|
||||||
|
|
||||||
char strFVal[10];
|
|
||||||
|
|
||||||
void wCycle()
|
|
||||||
{
|
|
||||||
static int sec = 0;
|
|
||||||
static short stp = 100;
|
|
||||||
if(stp == 100){
|
|
||||||
stp = 0;
|
|
||||||
sec++;
|
|
||||||
if (sec == 59){
|
|
||||||
sec = 0;
|
|
||||||
publishMin();
|
|
||||||
}
|
|
||||||
getTemp();
|
|
||||||
publishSec();
|
|
||||||
}
|
|
||||||
if((stp % 20) == 0){
|
|
||||||
showLCD();
|
|
||||||
}
|
|
||||||
if((stp) == 60){
|
|
||||||
float p, t, h;
|
|
||||||
bme.read(p, t, h, BME280::TempUnit_Celsius, BME280::PresUnit_torr);
|
|
||||||
//if (isnan(pres))
|
|
||||||
pres = p;
|
|
||||||
//else pres += (p - pres) * 0.05;
|
|
||||||
//if (isnan(temp2))
|
|
||||||
temp2 = t;
|
|
||||||
//else temp2 += (t - temp2) * 0.05;
|
|
||||||
//if (isnan(hum))
|
|
||||||
hum = h;
|
|
||||||
//else hum += (h - hum) * 0.05;
|
|
||||||
}
|
|
||||||
readDI();
|
|
||||||
movSens();
|
|
||||||
/* if (Flood == true)
|
|
||||||
pcf8574.write(2, LOW);
|
|
||||||
else
|
|
||||||
pcf8574.write(2, HIGH);*/
|
|
||||||
stp++;
|
|
||||||
} // loop()
|
|
||||||
|
|
||||||
|
|
||||||
void movSens()
|
|
||||||
{
|
|
||||||
adc = analogRead(A0);
|
|
||||||
if (MS != pcf8574.read(4)){
|
|
||||||
MS = pcf8574.read(4);
|
|
||||||
client.publish("/esp8266/move", String(MS).c_str());
|
|
||||||
}
|
|
||||||
//Dark
|
|
||||||
if ((adc < (ls.i - ld.i)) && MS){
|
|
||||||
pcf8574.write(5, LOW); //digitalWrite(LED_STRIPE, LOW);
|
|
||||||
}
|
|
||||||
//Light
|
|
||||||
if ((adc > (ls.i + ld.i)) || !MS){
|
|
||||||
pcf8574.write(5, HIGH); //digitalWrite(LED_STRIPE, HIGH);
|
|
||||||
}
|
|
||||||
if (MS == true)
|
|
||||||
lcd.setBacklight(255);
|
|
||||||
else
|
|
||||||
lcd.setBacklight(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void getTemp()
|
|
||||||
{
|
|
||||||
static bool readTemp = false;
|
|
||||||
static byte nSens = 0;
|
|
||||||
if (readTemp){
|
|
||||||
sensors.setWaitForConversion(false);
|
|
||||||
sensors.requestTemperatures();
|
|
||||||
readTemp = !readTemp;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
//float t = sensors.getTempC(outTemp);
|
|
||||||
float t = sensors.getTempC(da[nSens]);//ByIndex(nSens);
|
|
||||||
Serial.print(nSens);
|
|
||||||
Serial.print(" Temp readed=");
|
|
||||||
Serial.println(t);
|
|
||||||
//to[0] = t;
|
|
||||||
if ((t > -127) && (t < 85)){
|
|
||||||
switch(nSens){
|
|
||||||
case 0:
|
|
||||||
temp1 += (t - temp1) * 0.05;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
tHolTop += (t - tHolTop) * 0.05;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
tHolDown += (t - tHolDown) * 0.05;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
tMoroz += (t - tMoroz) * 0.05;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (++nSens > 3){
|
|
||||||
nSens = 0;
|
|
||||||
readTemp = !readTemp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void showLCD()
|
|
||||||
{
|
|
||||||
char outS[16];
|
|
||||||
String s1, s2;
|
|
||||||
//lcd.clear();
|
|
||||||
switch (sLCDPage){
|
|
||||||
case 0:
|
|
||||||
s1 = String(temp1, 1);
|
|
||||||
s2 = String(temp2, 1);
|
|
||||||
snprintf(outS, 17, "O:%5sC I:%4sC ", s1.c_str(), s2.c_str());
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(outS);
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
s1 = String(hum, 1);
|
|
||||||
s2 = String(pres, 0);
|
|
||||||
snprintf(outS, 17, "H:%4s%% Pr:%2smm", s1.c_str(), s2.c_str());
|
|
||||||
lcd.print(outS);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
snprintf(outS, 17, "L:%04d SP:%03d %d ", adc, ls.i, ld.i);
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(outS);
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
s1 = String(hum, 1);
|
|
||||||
s2 = String(hic, 1);
|
|
||||||
snprintf(outS, 17, "H:%4s%% HI:%4sC ", s1.c_str(), s2.c_str());
|
|
||||||
lcd.print(outS);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
snprintf(outS, 17, "L:%04d SP:%03d %d", adc, ls.i, ld.i);
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(outS);
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
snprintf(outS, 17, "C:%03.2fH:%03.2f", float(wcC.i) / 100.0, float(wcH.i) / 100.0);
|
|
||||||
lcd.print(outS);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
s1 = String(temp1, 1);
|
|
||||||
s2 = String(tMoroz, 1);
|
|
||||||
snprintf(outS, 17, "O:%4sC M:%4sC ", s1.c_str(), s2.c_str());
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(outS);
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
s1 = String(tHolTop, 1);
|
|
||||||
s2 = String(tHolDown, 1);
|
|
||||||
snprintf(outS, 17, "H:%4sC HM:%4sC", s1.c_str(), s2.c_str());
|
|
||||||
lcd.print(outS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void initLCD(){
|
|
||||||
int error;
|
|
||||||
Serial.println("LCD...");
|
|
||||||
Serial.println("Dose: check for LCD");
|
|
||||||
|
|
||||||
// See http://playground.arduino.cc/Main/I2cScanner
|
|
||||||
Wire.begin();
|
|
||||||
Wire.beginTransmission(0x38);
|
|
||||||
error = Wire.endTransmission();
|
|
||||||
Serial.print("Error: ");
|
|
||||||
Serial.print(error);
|
|
||||||
|
|
||||||
if (error == 0) {
|
|
||||||
Serial.println(": LCD found.");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Serial.println(": LCD not found.");
|
|
||||||
} // if
|
|
||||||
lcd.begin(16, 2); // initialize the lcd
|
|
||||||
lcd.setBacklight(255);
|
|
||||||
lcd.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*void handleRoot() {
|
|
||||||
digitalWrite ( led, 0 );
|
|
||||||
char temp[400];
|
|
||||||
int sec = millis() / 1000;
|
|
||||||
int min = sec / 60;
|
|
||||||
int hr = min / 60;
|
|
||||||
|
|
||||||
snprintf ( temp, 400,
|
|
||||||
|
|
||||||
"<html>\
|
|
||||||
<head>\
|
|
||||||
<meta http-equiv='refresh' content='5'/>\
|
|
||||||
<title>ESP8266 Demo</title>\
|
|
||||||
<style>\
|
|
||||||
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
|
|
||||||
</style>\
|
|
||||||
</head>\
|
|
||||||
<body>\
|
|
||||||
<h1>Hello from ESP8266!</h1>\
|
|
||||||
<p>Uptime: %02d:%02d:%02d</p>\
|
|
||||||
</body>\
|
|
||||||
</html>",
|
|
||||||
|
|
||||||
hr, min % 60, sec % 60
|
|
||||||
);
|
|
||||||
server.send ( 200, "text/html", temp );
|
|
||||||
//digitalWrite ( led, 1 );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void handleNotFound() {
|
|
||||||
// digitalWrite ( led, 0 );
|
|
||||||
String message = "File Not Found\n\n";
|
|
||||||
message += "URI: ";
|
|
||||||
message += server.uri();
|
|
||||||
message += "\nMethod: ";
|
|
||||||
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
|
|
||||||
message += "\nArguments: ";
|
|
||||||
message += server.args();
|
|
||||||
message += "\n";
|
|
||||||
// message += test().c_str();
|
|
||||||
|
|
||||||
for ( uint8_t i = 0; i < server.args(); i++ ) {
|
|
||||||
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
server.send ( 404, "text/plain", message );
|
|
||||||
//digitalWrite ( led, 1 );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void handleJSON()
|
|
||||||
{
|
|
||||||
//digitalWrite ( led, 0 );
|
|
||||||
pcf8574.write(7, LOW);
|
|
||||||
|
|
||||||
// Allocate JsonBuffer
|
|
||||||
// Use arduinojson.org/assistant to compute the capacity.
|
|
||||||
|
|
||||||
StaticJsonBuffer<500> jsonBuffer;
|
|
||||||
|
|
||||||
// Create the root object
|
|
||||||
JsonObject& root = jsonBuffer.createObject();
|
|
||||||
|
|
||||||
root.set<float>("temp1", temp1);
|
|
||||||
root.set<float>("temp2", temp2);
|
|
||||||
root.set<float>("press", pres);
|
|
||||||
root.set<float>("hum", hum);
|
|
||||||
root.set<float>("vlzem", 0.0);
|
|
||||||
root.set<float>("qc", float(wcC.i) / 100.0);
|
|
||||||
root.set<float>("qh", float(wcH.i) / 100.0);
|
|
||||||
root.set<float>("sp", ls.i);
|
|
||||||
root.set<float>("db", ld.i);
|
|
||||||
root.set<int>("vlsp", adc);
|
|
||||||
root.set<bool>("flood", Flood);
|
|
||||||
// Create the "analog" array
|
|
||||||
|
|
||||||
String s;
|
|
||||||
root.printTo(s);
|
|
||||||
server.send(200, "application/json", s);
|
|
||||||
pcf8574.write(7, HIGH);
|
|
||||||
//digitalWrite ( led, 0 );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void handleData()
|
|
||||||
{
|
|
||||||
//String inArgs = "";
|
|
||||||
char temp[100];
|
|
||||||
char tm[3];
|
|
||||||
String html;
|
|
||||||
|
|
||||||
pcf8574.write(7, LOW);
|
|
||||||
int sec = millis() / 1000;
|
|
||||||
int min = sec / 60;
|
|
||||||
int hr = min / 60;
|
|
||||||
|
|
||||||
if (server.args() > 0){
|
|
||||||
for (int i = 0; i < server.args(); i++) {
|
|
||||||
if (server.argName(i).equals("wcc")){
|
|
||||||
wcC.i = int(server.arg(i).toFloat() * 100.0f);
|
|
||||||
writeEEPROM("cc", wcC);
|
|
||||||
//inArgs += "<p>Write to wcc value: " + server.arg(i) + "</p>";
|
|
||||||
}
|
|
||||||
if (server.argName(i).equals("wch")){
|
|
||||||
wcH.i = int(server.arg(i).toFloat() * 100.0f) ;
|
|
||||||
writeEEPROM("ch", wcH);
|
|
||||||
//inArgs += "<p>Write to wcc value: " + server.arg(i) + "</p>";
|
|
||||||
}
|
|
||||||
if (server.argName(i).equals("ls_set")){
|
|
||||||
ls.i = server.arg(i).toInt();
|
|
||||||
writeEEPROM("ls", ls);
|
|
||||||
}
|
|
||||||
if (server.argName(i).equals("ls_db")){
|
|
||||||
ld.i = server.arg(i).toInt();
|
|
||||||
writeEEPROM("ld", ld);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
html = "<html>";
|
|
||||||
html += "<head>";
|
|
||||||
html += "<meta http-equiv='refresh' content='5'/>";
|
|
||||||
html += "<title>ESP8266 Demo</title>";
|
|
||||||
html += "<style>body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>";
|
|
||||||
html += "</head>";
|
|
||||||
html += "<body>";
|
|
||||||
html += "<h1>Hello from ESP8266!</h1>";
|
|
||||||
snprintf(tm, 3, "%02d", hr);
|
|
||||||
html += "<p>Uptime: " + String(tm);
|
|
||||||
snprintf(tm, 3, "%02d", min % 60);
|
|
||||||
html += ":" + String(tm);
|
|
||||||
snprintf(tm, 3, "%02d", sec % 60);
|
|
||||||
html += ":" + String(tm) + String("</p>");
|
|
||||||
sprintf(temp, "<p>Cold Water: %6.2f m3</p><p>Hot Water: %6.2f m3</p><p>Temp: %3.3fC</p><p>LSet: %d, LDB: %d</p>", float(wcC.i) / 100.0, float(wcH.i) / 100.0, temp1, ls.i, ld.i);
|
|
||||||
html += String(temp);
|
|
||||||
html += "</body></html>";
|
|
||||||
|
|
||||||
server.send ( 200, "text/html", html );
|
|
||||||
pcf8574.write(7, HIGH);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
void initWiFi()
|
|
||||||
{
|
|
||||||
//WiFi.mode(WIFI_STA);
|
|
||||||
WiFi.begin(ssid, password);
|
|
||||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
Serial.println("");
|
|
||||||
Serial.print("Connected to ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
if (MDNS.begin(host)) {
|
|
||||||
Serial.println("MDNS responder started");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*server.on ("/", handleData);
|
|
||||||
server.on("/data", handleData);
|
|
||||||
server.on("/json", handleJSON);
|
|
||||||
server.on ("/inline", []() {
|
|
||||||
server.send ( 200, "text/plain", "this works as well" );
|
|
||||||
} );
|
|
||||||
server.onNotFound ( handleNotFound );
|
|
||||||
server.begin();
|
|
||||||
Serial.println ( "HTTP server started" );*/
|
|
||||||
|
|
||||||
Serial.println("Ready");
|
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
}
|
|
||||||
|
|
||||||
void initTemp()
|
|
||||||
{
|
|
||||||
//DeviceAddress da[4];
|
|
||||||
sensors.begin();
|
|
||||||
Serial.println("InitTemp");
|
|
||||||
//oneWire.reset_search();
|
|
||||||
for (int i = 0; i < 4; i++){
|
|
||||||
//sensors.getAddress(da[i], i);
|
|
||||||
sensors.setResolution(da[i], 12);
|
|
||||||
//printAddress(da[i]);
|
|
||||||
}
|
|
||||||
//sensors.getAddress(outTemp, 0);
|
|
||||||
//sensors.setResolution(outTemp, 12);
|
|
||||||
sensors.setWaitForConversion(true);
|
|
||||||
sensors.requestTemperatures();
|
|
||||||
Serial.println("Request Temp");
|
|
||||||
/*printAddress(outTemp);
|
|
||||||
printAddress(holTop);
|
|
||||||
printAddress(holDown);
|
|
||||||
printAddress(moroz);*/
|
|
||||||
temp1 = sensors.getTempC(da[0]);
|
|
||||||
Serial.println(temp1);
|
|
||||||
tHolTop = sensors.getTempC(da[1]);
|
|
||||||
Serial.println(tHolTop);
|
|
||||||
tHolDown = sensors.getTempC(da[2]);
|
|
||||||
Serial.println(tHolDown);
|
|
||||||
tMoroz = sensors.getTempC(da[3]);
|
|
||||||
Serial.println(tMoroz);
|
|
||||||
/*delay(100);
|
|
||||||
tHolTop = sensors.getTempCByIndex(1);
|
|
||||||
delay(100);
|
|
||||||
tHolDown = sensors.getTempCByIndex(2);
|
|
||||||
delay(100);
|
|
||||||
tMoroz = sensors.getTempCByIndex(0);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*void readEEPROM()
|
|
||||||
{
|
|
||||||
wcC.b[0] = EEPROM.read(0);
|
|
||||||
wcC.b[1] = EEPROM.read(1);
|
|
||||||
wcC.b[2] = EEPROM.read(2);
|
|
||||||
wcC.b[3] = EEPROM.read(3);
|
|
||||||
|
|
||||||
wcH.b[0] = EEPROM.read(4);
|
|
||||||
wcH.b[1] = EEPROM.read(5);
|
|
||||||
wcH.b[2] = EEPROM.read(6);
|
|
||||||
wcH.b[3] = EEPROM.read(7);
|
|
||||||
|
|
||||||
ls.b[0] = EEPROM.read(8);
|
|
||||||
ls.b[1] = EEPROM.read(9);
|
|
||||||
ls.b[2] = EEPROM.read(10);
|
|
||||||
ls.b[3] = EEPROM.read(11);
|
|
||||||
|
|
||||||
ld.b[0] = EEPROM.read(12);
|
|
||||||
ld.b[1] = EEPROM.read(13);
|
|
||||||
ld.b[2] = EEPROM.read(14);
|
|
||||||
ld.b[3] = EEPROM.read(15);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*void writeEEPROM(const char tip[2], uFloat val)
|
|
||||||
{
|
|
||||||
short shft = -1;
|
|
||||||
if (strcmp(tip, "cc") == 0) {
|
|
||||||
shft = 0;
|
|
||||||
//Serial.print("Write cold counter: ");
|
|
||||||
//Serial.println(val.f);
|
|
||||||
}
|
|
||||||
if (strcmp(tip, "ch") == 0) {
|
|
||||||
shft = 4;
|
|
||||||
//Serial.print("Write Hot counter: ");
|
|
||||||
//Serial.println(val.f);
|
|
||||||
}
|
|
||||||
if (strcmp(tip, "ls") == 0) {
|
|
||||||
shft = 8;
|
|
||||||
//Serial.print("Light Sensor Set: ");
|
|
||||||
//Serial.println(val.i);
|
|
||||||
}
|
|
||||||
if (strcmp(tip, "ld") == 0) {
|
|
||||||
shft = 12;
|
|
||||||
//Serial.print("Light Sensor DB: ");
|
|
||||||
//Serial.println(val.i);
|
|
||||||
}
|
|
||||||
if (shft == -1) return;
|
|
||||||
|
|
||||||
EEPROM.write(shft, val.b[0]);
|
|
||||||
EEPROM.write(shft + 1, val.b[1]);
|
|
||||||
EEPROM.write(shft + 2, val.b[2]);
|
|
||||||
EEPROM.write(shft + 3, val.b[3]);
|
|
||||||
EEPROM.commit();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void readDI()
|
|
||||||
{
|
|
||||||
/*if (hot_dbnc.update()){
|
|
||||||
if (hot_dbnc.read() == 1){
|
|
||||||
wcH.i += 1;
|
|
||||||
//wcH.f += 0.01;
|
|
||||||
if (fabs(old_wcH - wcH.i) >= 5){
|
|
||||||
writeEEPROM("ch", wcH);
|
|
||||||
old_wcH = wcH.i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cold_dbnc.update()){
|
|
||||||
if (cold_dbnc.read() == 1)
|
|
||||||
wcC.i += 1;
|
|
||||||
if (fabs(old_wcC - wcC.i) >= 5){
|
|
||||||
writeEEPROM("cc", wcC);
|
|
||||||
old_wcC = wcC.i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!pcf8574.read(6))
|
|
||||||
Flood = true;
|
|
||||||
if (!pcf8574.read(0)) Flood = false;*/
|
|
||||||
if (pcf8574.read(1) != bMLCD){
|
|
||||||
if (bMLCD == false){
|
|
||||||
sLCDPage++;
|
|
||||||
if (sLCDPage > 3) sLCDPage = 0;
|
|
||||||
}
|
|
||||||
bMLCD = !bMLCD;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void callback(String topic, byte* message, unsigned int length) {
|
|
||||||
Serial.print("Message arrived on topic: ");
|
|
||||||
// "Сообщение прибыло в топик: "
|
|
||||||
Serial.print(topic);
|
|
||||||
Serial.print(". Message: "); // ". Сообщение: "
|
|
||||||
String messageTemp;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < length; i++) {
|
|
||||||
Serial.print((char)message[i]);
|
|
||||||
messageTemp += (char)message[i];
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
void reconnect() {
|
|
||||||
// заново запускаем цикл, пока не подключимся:
|
|
||||||
//while (!client.connected()) {
|
|
||||||
Serial.print("Attempting MQTT connection...");
|
|
||||||
// "Попытка подключиться к MQTT-брокеру... "
|
|
||||||
|
|
||||||
// Пытаемся подключиться:
|
|
||||||
if (client.connect("ESP8266Client")) {
|
|
||||||
Serial.println("connected"); // "подключен"
|
|
||||||
// подписываемся или переподписываемся на топик;
|
|
||||||
// можно подписаться не только на один, а на несколько топиков
|
|
||||||
// (что касается конкретно этого примера, то это позволит
|
|
||||||
// управлять большим количеством светодиодов):
|
|
||||||
//client.subscribe("esp8266/qc");
|
|
||||||
//client.subscribe("esp8266/qh");
|
|
||||||
} else {
|
|
||||||
Serial.print("failed, rc="); // "подключение не удалось"
|
|
||||||
Serial.print(client.state());
|
|
||||||
Serial.println(" try again in 5 seconds");
|
|
||||||
// "5 секунд до следующей попытки"
|
|
||||||
// ждем 5 секунд перед тем, как попробовать снова:
|
|
||||||
//delay(5000);
|
|
||||||
}
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
void printAddress(DeviceAddress deviceAddress)
|
|
||||||
{
|
|
||||||
for (uint8_t i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
// zero pad the address if necessary
|
|
||||||
if (deviceAddress[i] < 16) Serial.print("0");
|
|
||||||
Serial.print(deviceAddress[i], HEX);
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
void publishSec()
|
|
||||||
{
|
|
||||||
if (!client.connected()) {
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
if(!client.loop())
|
|
||||||
client.connect("ESP8266Client");
|
|
||||||
if (client.connected()) {
|
|
||||||
pcf8574.write(3, LOW);
|
|
||||||
dtostrf(temp1, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/temp_out", strFVal);
|
|
||||||
dtostrf(temp2, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/temp_in", strFVal);
|
|
||||||
dtostrf(hum, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/humidity", strFVal);
|
|
||||||
dtostrf(pres, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/pressure", strFVal);
|
|
||||||
dtostrf(float(wcC.i) / 100.0, 6, 2, strFVal);
|
|
||||||
/*client.publish("/esp8266/qCold", strFVal);
|
|
||||||
dtostrf(float(wcH.i) / 100.0, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/qHot", strFVal);
|
|
||||||
itoa(ls.i, strFVal, 10);*/
|
|
||||||
client.publish("/esp8266/light_sp", strFVal);
|
|
||||||
itoa(ld.i, strFVal, 10);
|
|
||||||
client.publish("/esp8266/light_db", strFVal);
|
|
||||||
itoa(adc, strFVal, 10);
|
|
||||||
client.publish("/esp8266/light_cur", strFVal);
|
|
||||||
//client.publish("/esp8266/flood", String(Flood).c_str());
|
|
||||||
dtostrf(tHolTop, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/hol_top", strFVal);
|
|
||||||
dtostrf(tHolDown, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/hol_down", strFVal);
|
|
||||||
dtostrf(tMoroz, 6, 2, strFVal);
|
|
||||||
client.publish("/esp8266/moroz", strFVal);
|
|
||||||
pcf8574.write(3, HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void publishMin()
|
|
||||||
{
|
|
||||||
if (!client.connected()) {
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
if(!client.loop())
|
|
||||||
client.connect("ESP8266Client");
|
|
||||||
if (client.connected()) {
|
|
||||||
pcf8574.write(7, LOW);
|
|
||||||
dtostrf(temp1, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/temp_out", strFVal);
|
|
||||||
dtostrf(temp2, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/temp_in", strFVal);
|
|
||||||
dtostrf(hum, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/humidity", strFVal);
|
|
||||||
dtostrf(pres, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/pressure", strFVal);
|
|
||||||
itoa(ls.i, strFVal, 10);
|
|
||||||
client.publish("/home/kuh/light_sp", strFVal);
|
|
||||||
itoa(ld.i, strFVal, 10);
|
|
||||||
client.publish("/home/kuh/light_db", strFVal);
|
|
||||||
itoa(adc, strFVal, 10);
|
|
||||||
client.publish("/home/kuh/light_cur", strFVal);
|
|
||||||
dtostrf(tHolTop, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/hol_top", strFVal);
|
|
||||||
dtostrf(tHolDown, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/hol_down", strFVal);
|
|
||||||
dtostrf(tMoroz, 6, 1, strFVal);
|
|
||||||
client.publish("/home/kuh/moroz", strFVal);
|
|
||||||
pcf8574.write(7, HIGH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
This directory is intended for PIO Unit Testing and project tests.
|
|
||||||
|
|
||||||
Unit Testing is a software testing method by which individual units of
|
|
||||||
source code, sets of one or more MCU program modules together with associated
|
|
||||||
control data, usage procedures, and operating procedures, are tested to
|
|
||||||
determine whether they are fit for use. Unit testing finds problems early
|
|
||||||
in the development cycle.
|
|
||||||
|
|
||||||
More information about PIO Unit Testing:
|
|
||||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
|
||||||
Reference in New Issue
Block a user