First commit

This commit is contained in:
2020-08-01 13:47:02 +03:00
commit ac18805ff4
142 changed files with 8325 additions and 0 deletions

5
ESP12SmallRoom/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@@ -0,0 +1,67 @@
# 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

View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@@ -0,0 +1,39 @@
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

View File

@@ -0,0 +1,19 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#include <Arduino.h>
class leds
{
private:
int ledPin;
bool inv, state;
int onMS;
unsigned long curMS;
public:
leds(int ledPin, int onms = 300, bool inverse = false);
//~leds();
void start();
void tick();
};
#endif

46
ESP12SmallRoom/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

View File

@@ -0,0 +1,18 @@
; 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:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
board_build.ldscript = eagle.flash.1m.ld
board_build.f_cpu = 26000000L
upload_protocol = espota
upload_port = 192.168.1.7

View File

@@ -0,0 +1,24 @@
#include <leds.h>
leds::leds(int pinLED, int onms, bool inverse)
{
ledPin = pinLED;
inv = inverse;
onMS = onms;
state = false;
}
void leds::start()
{
curMS = millis();
state = true;
digitalWrite(ledPin, !inv);
}
void leds::tick()
{
if(state && ((curMS + onMS) < millis())){
state = false;
digitalWrite(ledPin, inv);
}
}

175
ESP12SmallRoom/src/main.cpp Normal file
View File

@@ -0,0 +1,175 @@
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Wire.h>
#include <Adafruit_HTU21DF.h>
#include <PubSubClient.h>
#include <leds.h>
#define LED_BLUE D5 //GPIO14
#define LED_GREEN D6 //GPIO12
#define LED_RED D7 //GPIO13
#define PWR_SENS D8 //GPIO13
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
WiFiClient espClient;
PubSubClient client(espClient);
leds lGreen(LED_GREEN, 200);
leds lRed(LED_RED, 200);
leds lBlue(LED_BLUE, 200);
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
float temp, rel_hum;
bool izm = false;
unsigned long cRun;
int minCnt = 0;
int measCnt = 1;
void reconnect();
void publishMin();
void publishSec();
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.setOutputPower(20.5f);
WiFi.hostname("ESP-SmallRoom");
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
//Serial.println("Connection Failed! Rebooting...");
// "Соединиться не удалось! Перезагрузка..."
delay(5000);
ESP.restart();
}
digitalWrite(LED_BUILTIN, !WiFi.isConnected());
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();
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
pinMode(LED_RED, OUTPUT);
pinMode(PWR_SENS, OUTPUT);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
digitalWrite(LED_RED, LOW);
// Serial.begin(115200);
Serial.println("HTU21D-F");
digitalWrite(PWR_SENS, HIGH);
delay(200);
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
temp = htu.readTemperature();
rel_hum = htu.readHumidity();
//digitalWrite(PWR_SENS, LOW);
client.setServer(mqtt_server, 1883);
cRun = millis();
}
void loop() {
ArduinoOTA.handle();
lGreen.tick();
lRed.tick();
lBlue.tick();
if (!client.connected()) {
reconnect();
}
client.loop();
if(cRun + 999 < millis()){
cRun = millis();
if(measCnt == 0){
temp += (htu.readTemperature() - temp) / 6.0f;
rel_hum += (htu.readHumidity() - rel_hum) / 6.0f;
digitalWrite(PWR_SENS, LOW);
}
if(++measCnt == 9){
digitalWrite(PWR_SENS, HIGH);
measCnt = 0;
}
//Serial.print("T: ");Serial.print(temp);Serial.print("\tH: ");Serial.println(rel_hum);
if(++minCnt == 59){
publishMin();
minCnt = 0;
}
if(minCnt % 10 == 0) publishSec();
}
}
void reconnect() {
lRed.start();
//digitalWrite(LED_RED, HIGH);
//Serial.print("Attempting MQTT connection...");
// "Попытка подключиться к MQTT-брокеру... "
// Пытаемся подключиться:
if (client.connect("ESPSmallRoom")) {
//Serial.println("connected"); // "подключен"
// подписываемся или переподписываемся на топик;
// можно подписаться не только на один, а на несколько топиков
} else {
//Serial.print("failed, rc="); // "подключение не удалось"
//Serial.print(client.state());
//Serial.println(" try again in 5 seconds");
}
//delay(100);
//digitalWrite(LED_RED, LOW);
}
void publishMin()
{
char strFVal[11];
if (client.connected()) {
lGreen.start();
//digitalWrite(LED_BLUE, HIGH);
if(!isnan(temp)){
dtostrf(temp, 6, 1, strFVal);
client.publish("/home/smallroom/temp", strFVal);
}
if(!isnan(rel_hum)){
dtostrf(rel_hum, 6, 1, strFVal);
client.publish("/home/smallroom/rel_hum", strFVal);
}
itoa(cRun, strFVal, 10);
client.publish("/home/smallroom/millis", strFVal);
//digitalWrite(LED_BLUE, LOW);
}
}
void publishSec()
{
char strFVal[11];
if (client.connected()) {
lBlue.start();
//digitalWrite(LED_GREEN, HIGH);
if(!isnan(temp)){
dtostrf(temp, 7, 3, strFVal);
client.publish("/hometest/smallroom/temp", strFVal);
}
if(!isnan(rel_hum)){
dtostrf(rel_hum, 7, 3, strFVal);
client.publish("/hometest/smallroom/rel_hum", strFVal);
}
itoa(WiFi.RSSI(), strFVal, 10);
client.publish("/hometest/smallroom/RSSI", strFVal);
itoa(cRun, strFVal, 10);
client.publish("/hometest/smallroom/millis", strFVal);
//digitalWrite(LED_GREEN, LOW);
}
}

View File

@@ -0,0 +1,11 @@
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

5
ESP_BigRoom/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
ESP_BigRoom/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
ESP_BigRoom/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@@ -0,0 +1,39 @@
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

View File

@@ -0,0 +1,30 @@
// #ifndef __AMQTT__
// #define __AMQTT__
// //#include <main.h>
// #include <Arduino.h>
// #include <ArduinoOTA.h>
// #include <Ticker.h>
// #include <AsyncMqttClient.h>
// const char* ssid = "wf-home";
// const char* password = "0ndthnrf";
// const char* mqtt_server = "192.168.1.250";
// AsyncMqttClient mqttClient;
// Ticker mqttReconnectTimer;
// WiFiEventHandler wifiConnectHandler;
// WiFiEventHandler wifiDisconnectHandler;
// Ticker wifiReconnectTimer;
// void connectToWifi();
// void connectToMqtt();
// void onWifiConnect(const WiFiEventStationModeGotIP& event);
// void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
// void onMqttConnect(bool sessionPresent);
// void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
// void onMqttSubscribe(uint16_t packetId, uint8_t qos);
// void onMqttUnsubscribe(uint16_t packetId);
// void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
// void onMqttPublish(uint16_t packetId);
// #endif

View File

@@ -0,0 +1,19 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#include <Arduino.h>
class leds
{
private:
int ledPin;
bool inv, state;
int onMS;
unsigned long curMS;
public:
leds(int ledPin, int onms = 300, bool inverse = false);
//~leds();
void start();
void tick();
};
#endif

View File

@@ -0,0 +1,18 @@
// #ifndef __MAIN__
// #define __MAIN__
// #include <Arduino.h>
// #include <ArduinoOTA.h>
// #include <Ticker.h>
// #include <AsyncMqttClient.h>
// #include "Adafruit_HTU21DF.h"
// #define R_LED GPIO0
// #define G_LED GPIO2
// #define B_LED GPIO14
// bool meas = false;
// short minCnt;
// #endif // __MAIN__

46
ESP_BigRoom/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

View File

@@ -0,0 +1,19 @@
; 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 = esp12e
framework = arduino
board_build.f_cpu = 26000000L
board_build.ldscript = eagle.flash.1m.ld
;board_build.flash_mode = dout
upload_protocol = espota
upload_port = 192.168.1.131

72
ESP_BigRoom/src/amqtt.cpp Normal file
View File

@@ -0,0 +1,72 @@
// #include <amqtt.h>
// void connectToWifi() {
// Serial.println("Connecting to Wi-Fi...");
// WiFi.begin(ssid, password);
// }
// void connectToMqtt() {
// Serial.println("Connecting to MQTT...");
// //mqttClient.connect();
// }
// void onWifiConnect(const WiFiEventStationModeGotIP& event) {
// Serial.println("Connected to Wi-Fi.");
// Serial.print("IP: ");
// Serial.println(WiFi.localIP());
// connectToMqtt();
// }
// void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
// Serial.println("Disconnected from Wi-Fi.");
// mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
// wifiReconnectTimer.once(2, connectToWifi);
// }
// void onMqttConnect(bool sessionPresent) {
// Serial.println("Connected to MQTT.");
// Serial.print("Session present: ");
// Serial.println(sessionPresent);
// //uint16_t packetIdSub =
// // Serial.print("Subscribing Lamp1, packetId: ");
// // Serial.println(packetIdSub);
// //packetIdSub = mqttClient.subscribe("/home/kor/lamp2_set", 1);
// //Serial.print("Subscribing Lamp2, packetId: ");
// //Serial.println(packetIdSub);
// //Serial.println("Publishing at Lamp 1");
// //mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
// //Serial.println("Publishing at Lamp 2");
// }
// void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
// Serial.println("Disconnected from MQTT.");
// if (WiFi.isConnected()) {
// mqttReconnectTimer.once(2, connectToMqtt);
// }
// }
// void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
// // Serial.println("Subscribe acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// // Serial.print(" qos: ");
// // Serial.println(qos);
// }
// void onMqttUnsubscribe(uint16_t packetId) {
// // Serial.println("Unsubscribe acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// }
// void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
// if(strcmp(topic, "/home/kor/lamp1_set") == 0){
// }
// }
// void onMqttPublish(uint16_t packetId) {
// // Serial.println("Publish acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// }

24
ESP_BigRoom/src/leds.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include <leds.h>
leds::leds(int pinLED, int onms, bool inverse)
{
ledPin = pinLED;
inv = inverse;
onMS = onms;
state = false;
}
void leds::start()
{
curMS = millis();
state = true;
digitalWrite(ledPin, !inv);
}
void leds::tick()
{
if(state && ((curMS + onMS) < millis())){
state = false;
digitalWrite(ledPin, inv);
}
}

266
ESP_BigRoom/src/main.cpp Normal file
View File

@@ -0,0 +1,266 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <leds.h>
#include "Adafruit_HTU21DF.h"
#define R_LED (0)
#define G_LED (2)
#define B_LED (14)
#define P_SENS (12)
#define MOV_SENS (13)
bool meas = false;
short minCnt;
bool send_move = false;
int old_mov = 0;
int adc = 0;
int lastADC = 0;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
unsigned long cRun;
float temp, rel_hum;
// bool dir = true;
// int dc = 0;
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
void connectToWifi();
void connectToMqtt();
void onWifiConnect(const WiFiEventStationModeGotIP& event);
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
void onMqttConnect(bool sessionPresent);
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
void onMqttSubscribe(uint16_t packetId, uint8_t qos);
void onMqttUnsubscribe(uint16_t packetId);
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
void onMqttPublish(uint16_t packetId);
leds b_led(B_LED);
leds g_led(G_LED);
leds r_led(R_LED);
void setup() {
Serial.begin(9600);
Serial.println("Booting"); // "Загрузка"
WiFi.mode(WIFI_STA);
WiFi.hostname("BigRoom");
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();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
pinMode(MOV_SENS, INPUT_PULLUP);
pinMode(P_SENS, OUTPUT);
pinMode(R_LED, OUTPUT);
pinMode(G_LED, OUTPUT);
pinMode(B_LED, OUTPUT);
digitalWrite(P_SENS, HIGH);
delay(200);
Serial.println("Begin HTU");
if (!htu.begin()) {
while (1);
}
Serial.println("HTU Ok");
temp = htu.readTemperature();
rel_hum = htu.readHumidity();
Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
Serial.print("\t\t");
Serial.print("Humidity: "); Serial.print(rel_hum); Serial.println(" \%");
digitalWrite(R_LED, HIGH);
digitalWrite(P_SENS, LOW);
connectToWifi();
cRun = millis();
}
void loop() {
char v[11];
ArduinoOTA.handle();
g_led.tick();
if (digitalRead(MOV_SENS) != old_mov){
old_mov = digitalRead(MOV_SENS);
Serial.println("Change mov detected");
mqttClient.publish("/home/bigroom/move", 1, false, old_mov ? "1" : "0");
}
if(cRun + 999 < millis()){
cRun = millis();
//analogWrite(B_LED, dc);
/*if(dir){
dc += 64;
if(dc >= 959) dir = !dir;
}
else{
dc -= 64;
if(dc <= 64) dir = !dir;
}*/
//Serial.println(dc);
adc = analogRead(A0);
if(abs(adc - lastADC) > 20){
lastADC = adc;
itoa(adc, v, 10);
mqttClient.publish("/home/bigroom/light", 1, false, v);
}
if(meas){
Serial.println(adc);
temp += (htu.readTemperature() - temp) / 60.0f;
rel_hum += (htu.readHumidity() - rel_hum) / 60.0f;
Serial.print(cRun);
Serial.print("\t");
Serial.print(minCnt);
Serial.print("\t");
Serial.print("Temp: "); Serial.print(temp); Serial.print(" C");
Serial.print("\t\t");
Serial.print("Humidity: "); Serial.print(rel_hum); Serial.println(" \%");
digitalWrite(P_SENS, LOW);
meas = false;
}
else{
if(minCnt % 5 == 0){
digitalWrite(P_SENS, HIGH);
meas = true;
}
}
if(++minCnt == 60){
minCnt = 0;
if(mqttClient.connected()){
//char s[50];
g_led.start();
Serial.println("Begin Publish");
dtostrf(temp, 5, 1,v);
mqttClient.publish("/home/bigroom/temp", 0, false, v);
Serial.println("Publish1");
dtostrf(rel_hum, 5, 1,v);
mqttClient.publish("/home/bigroom/humid", 0, false, v);
Serial.println("Publish2");
//sprintf(s, "{temperatura: %.1f, humidity: %.1f}", temp, rel_hum);
//Serial.println(s);
//mqttClient.publish("/home/bigroom/climat", 0, false, s);
}
}
else if(minCnt % 10 == 0){
if(mqttClient.connected()) mqttClient.publish("/home/bigroom/millis", 0, false, itoa(millis(), v, 10));
//b_led.start();
}
}
}
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial.println("Connected to Wi-Fi.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
connectToMqtt();
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial.println("Disconnected from Wi-Fi.");
digitalWrite(B_LED, LOW);
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
}
void onMqttConnect(bool sessionPresent) {
Serial.println("Connected to MQTT.");
Serial.print("Session present: ");
Serial.println(sessionPresent);
digitalWrite(B_LED, HIGH);
digitalWrite(R_LED, LOW);
//uint16_t packetIdSub =
// Serial.print("Subscribing Lamp1, packetId: ");
// Serial.println(packetIdSub);
//packetIdSub = mqttClient.subscribe("/home/kor/lamp2_set", 1);
//Serial.print("Subscribing Lamp2, packetId: ");
//Serial.println(packetIdSub);
//Serial.println("Publishing at Lamp 1");
//mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
//Serial.println("Publishing at Lamp 2");
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
Serial.println("Disconnected from MQTT.");
digitalWrite(B_LED, LOW);
digitalWrite(R_LED, HIGH);
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
// Serial.println("Subscribe acknowledged.");
// Serial.print(" packetId: ");
// Serial.println(packetId);
// Serial.print(" qos: ");
// Serial.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
// Serial.println("Unsubscribe acknowledged.");
// Serial.print(" packetId: ");
// Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
if(strcmp(topic, "/home/kor/lamp1_set") == 0){
}
}
void onMqttPublish(uint16_t packetId) {
Serial.println("Publish acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
g_led.start();
}

11
ESP_BigRoom/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
ESP_Electro/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
ESP_Electro/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
ESP_Electro/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@@ -0,0 +1,39 @@
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

46
ESP_Electro/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

View File

@@ -0,0 +1,18 @@
; 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:esp07]
platform = espressif8266
;board = nodemcuv2
board = esp07
framework = arduino
board_build.ldscript = eagle.flash.1m.ld
upload_protocol = espota
upload_port = 192.168.1.136

208
ESP_Electro/src/main.cpp Normal file
View File

@@ -0,0 +1,208 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <EmonLib.h>
#define LED_WF (14)
#define LED_MQ (12)
#define LED_WRK (13)
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
unsigned long cRun = millis();
double curr;
int nSec, nSampl;
EnergyMonitor emon1;
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial.println("Connected to Wi-Fi.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
connectToMqtt();
digitalWrite(LED_WF, HIGH);
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial.println("Disconnected from Wi-Fi.");
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
digitalWrite(LED_WF, LOW);
}
void onMqttConnect(bool sessionPresent) {
Serial.println("Connected to MQTT.");
Serial.print("Session present: ");
Serial.println(sessionPresent);
digitalWrite(LED_MQ, HIGH);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
//Serial.println("Disconnected from MQTT.");
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(LED_MQ, LOW);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
Serial.println("Subscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
Serial.print(" qos: ");
Serial.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
Serial.println("Unsubscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
}
void onMqttPublish(uint16_t packetId) {
Serial.println("Publish acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void setup(){
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.hostname("Test");
Serial.begin(9600);
emon1.current(0, 30.0);
ArduinoOTA.onStart([]() {
Serial1.println("Start Update"); // "Начало OTA-апдейта"
});
ArduinoOTA.onEnd([]() {
Serial1.println("\nEnd Update"); // "Завершение OTA-апдейта"
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
//Serial1.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial1.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial1.println("Auth Failed");
// "Ошибка при аутентификации"
else if (error == OTA_BEGIN_ERROR) Serial1.println("Begin Failed");
// "Ошибка при начале OTA-апдейта"
else if (error == OTA_CONNECT_ERROR) Serial1.println("Connect Failed");
// "Ошибка при подключении"
else if (error == OTA_RECEIVE_ERROR) Serial1.println("Receive Failed");
// "Ошибка при получении данных"
else if (error == OTA_END_ERROR) Serial1.println("End Failed");
// "Ошибка при завершении OTA-апдейта"
});
ArduinoOTA.begin();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
pinMode(LED_WF, OUTPUT);
pinMode(LED_MQ, OUTPUT);
pinMode(LED_WRK, OUTPUT);
//pinMode(5, INPUT_PULLUP);
digitalWrite(LED_WF, LOW);
digitalWrite(LED_MQ, LOW);
digitalWrite(LED_WRK, LOW);
connectToWifi();
nSec = 0;
curr = -1;
nSampl = 0;
#ifdef ESP8266
Serial.println("ESP8266");
delay(1000);
#endif
}
void loop(){
static bool led_wrk = false;
ArduinoOTA.handle();
yield();
if(cRun + 999 < millis()){
cRun = millis();
double Irms = 0;
if(WiFi.isConnected()){
Irms = emon1.calcIrms(1480) - 0.5;
if(curr < 0){
curr = Irms;
}
else{
//curr += (Irms - curr) / 60;
curr += (Irms);
}
// Serial.print("Sec: ");
// yield();
// Serial.print(nSec);
// yield();
// Serial.print("\t");
// yield();
// Serial.print(Irms);
// yield();
// Serial.print("\t");
// yield();
// Serial.println(Irms * 233);
led_wrk = !led_wrk;
digitalWrite(LED_WRK, led_wrk);
nSampl++;
}
if(++nSec > 59){
nSec = 0;
curr = curr / (double)nSampl;
// Serial.print("Millis: ");
// yield();
// Serial.print(millis());
// yield();
// Serial.print("\t");
// yield();
// Serial.print(curr);
// yield();
// Serial.print("\t");
// yield();
// Serial.println(curr * 233);
if(nSampl > 0){
//Serial.println("Publish");
char v[7];
sprintf(v, "%.2f", curr);
mqttClient.publish("/home/kor/curr", 1, false, v);
}
nSampl = 0;
curr = -1;
}
}
}

11
ESP_Electro/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
ESP_Kor/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
ESP_Kor/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
ESP_Kor/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
ESP_Kor/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

46
ESP_Kor/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

17
ESP_Kor/platformio.ini Normal file
View File

@@ -0,0 +1,17 @@
;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
monitor_speed = 9600
upload_protocol = espota
upload_port = 192.168.1.6

194
ESP_Kor/src/main.cpp Normal file
View File

@@ -0,0 +1,194 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include "SdsDustSensor.h"
#define WIFI_SSID "wf-home"
#define WIFI_PASSWORD "0ndthnrf"
#define MQTT_SERV "192.168.1.250"
#define HOSTNAME "ESP_Kor"
#define LED_WF (D0)
#define LED_MQ (D3)
#define LED_WRK (D4)
int rxPin = D1;
int txPin = D2;
SdsDustSensor sds(rxPin, txPin);
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
void connectToWifi();
void connectToMqtt();
void onWifiConnect(const WiFiEventStationModeGotIP& event);
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
void onMqttConnect(bool sessionPresent);
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
void onMqttSubscribe(uint16_t packetId, uint8_t qos);
void onMqttUnsubscribe(uint16_t packetId);
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
void onMqttPublish(uint16_t packetId);
unsigned long cRun;
int cSec = 0;
void setup()
{
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.hostname(HOSTNAME);
ArduinoOTA.onStart([]() {
Serial.println("ArduinoOTA start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nArduinoOTA end");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA 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");
} 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");
}
});
ArduinoOTA.begin();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(MQTT_SERV, 1883);
sds.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(LED_WF, OUTPUT);
pinMode(LED_MQ, OUTPUT);
pinMode(LED_WRK, OUTPUT);
digitalWrite(LED_WF, HIGH);
digitalWrite(LED_MQ, HIGH);
cRun = millis();
}
void loop()
{
//static bool lwork = false;
static unsigned long stled = millis();
ArduinoOTA.handle();
if(cRun + 999 < millis()){
cRun = millis();
PmResult pm = sds.readPm();
if((stled + 300) < millis()) digitalWrite(LED_WRK, LOW);
//lwork = !lwork;
cSec++;
if (pm.isOk()) {
if(mqttClient.connected()){
digitalWrite(LED_WRK, HIGH);
stled = millis();
char v[6];
sprintf(v, "%.1f", pm.pm25);
mqttClient.publish("/home/kor/pm25", 1, false, v);
sprintf(v, "%.1f", pm.pm10);
mqttClient.publish("/home/kor/pm10", 1, false, v);
}
Serial.print(cRun); Serial.print("\t");
Serial.print("PM2.5 = ");
Serial.print(pm.pm25);
Serial.print(", PM10 = ");
Serial.println(pm.pm10);
cSec = 0;
}
}
}
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial.println("Connected to Wi-Fi.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
connectToMqtt();
digitalWrite(LED_WF, LOW);
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial.println("Disconnected from Wi-Fi.");
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
digitalWrite(LED_WF, HIGH);
}
void onMqttConnect(bool sessionPresent) {
Serial.println("Connected to MQTT.");
Serial.print("Session present: ");
Serial.println(sessionPresent);
digitalWrite(LED_MQ, LOW);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
//Serial.println("Disconnected from MQTT.");
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(LED_MQ, HIGH);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
Serial.println("Subscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
Serial.print(" qos: ");
Serial.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
Serial.println("Unsubscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
}
void onMqttPublish(uint16_t packetId) {
Serial.println("Publish acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}

11
ESP_Kor/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
ESP_MidRoom/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
ESP_MidRoom/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
ESP_MidRoom/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@@ -0,0 +1,39 @@
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

View File

@@ -0,0 +1,30 @@
// #ifndef __AMQTT__
// #define __AMQTT__
// //#include <main.h>
// #include <Arduino.h>
// #include <ArduinoOTA.h>
// #include <Ticker.h>
// #include <AsyncMqttClient.h>
// const char* ssid = "wf-home";
// const char* password = "0ndthnrf";
// const char* mqtt_server = "192.168.1.250";
// AsyncMqttClient mqttClient;
// Ticker mqttReconnectTimer;
// WiFiEventHandler wifiConnectHandler;
// WiFiEventHandler wifiDisconnectHandler;
// Ticker wifiReconnectTimer;
// void connectToWifi();
// void connectToMqtt();
// void onWifiConnect(const WiFiEventStationModeGotIP& event);
// void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
// void onMqttConnect(bool sessionPresent);
// void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
// void onMqttSubscribe(uint16_t packetId, uint8_t qos);
// void onMqttUnsubscribe(uint16_t packetId);
// void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
// void onMqttPublish(uint16_t packetId);
// #endif

View File

@@ -0,0 +1,19 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#include <Arduino.h>
class leds
{
private:
int ledPin;
bool inv, state;
int onMS;
unsigned long curMS;
public:
leds(int ledPin, int onms = 300, bool inverse = false);
//~leds();
void start();
void tick();
};
#endif

View File

@@ -0,0 +1,19 @@
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <Adafruit_BME280.h>
#include <MHZ19.h>
//#define POWER_SENS (7)
Adafruit_BME280 bme;
MHZ19 mhz19;
unsigned long crun;
uint32_t co2;
bool firstRun;
float p, t, h;
//uint16_t cntSec;
int light, lightPrev;

46
ESP_MidRoom/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

View File

@@ -0,0 +1,19 @@
; 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 = esp12e
framework = arduino
board_build.f_cpu = 26000000L
board_build.ldscript = eagle.flash.1m.ld
;board_build.flash_mode = dout
upload_protocol = espota
upload_port = 192.168.1.132

72
ESP_MidRoom/src/amqtt.cpp Normal file
View File

@@ -0,0 +1,72 @@
// #include <amqtt.h>
// void connectToWifi() {
// Serial.println("Connecting to Wi-Fi...");
// WiFi.begin(ssid, password);
// }
// void connectToMqtt() {
// Serial.println("Connecting to MQTT...");
// //mqttClient.connect();
// }
// void onWifiConnect(const WiFiEventStationModeGotIP& event) {
// Serial.println("Connected to Wi-Fi.");
// Serial.print("IP: ");
// Serial.println(WiFi.localIP());
// connectToMqtt();
// }
// void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
// Serial.println("Disconnected from Wi-Fi.");
// mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
// wifiReconnectTimer.once(2, connectToWifi);
// }
// void onMqttConnect(bool sessionPresent) {
// Serial.println("Connected to MQTT.");
// Serial.print("Session present: ");
// Serial.println(sessionPresent);
// //uint16_t packetIdSub =
// // Serial.print("Subscribing Lamp1, packetId: ");
// // Serial.println(packetIdSub);
// //packetIdSub = mqttClient.subscribe("/home/kor/lamp2_set", 1);
// //Serial.print("Subscribing Lamp2, packetId: ");
// //Serial.println(packetIdSub);
// //Serial.println("Publishing at Lamp 1");
// //mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
// //Serial.println("Publishing at Lamp 2");
// }
// void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
// Serial.println("Disconnected from MQTT.");
// if (WiFi.isConnected()) {
// mqttReconnectTimer.once(2, connectToMqtt);
// }
// }
// void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
// // Serial.println("Subscribe acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// // Serial.print(" qos: ");
// // Serial.println(qos);
// }
// void onMqttUnsubscribe(uint16_t packetId) {
// // Serial.println("Unsubscribe acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// }
// void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
// if(strcmp(topic, "/home/kor/lamp1_set") == 0){
// }
// }
// void onMqttPublish(uint16_t packetId) {
// // Serial.println("Publish acknowledged.");
// // Serial.print(" packetId: ");
// // Serial.println(packetId);
// }

32
ESP_MidRoom/src/leds.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include <leds.h>
leds::leds(int pinLED, int onms, bool inverse)
{
ledPin = pinLED;
inv = inverse;
onMS = onms;
state = false;
}
void leds::start()
{
curMS = millis();
state = true;
if(!inv)
analogWrite(ledPin, 100);
else
analogWrite(ledPin, 0);
//digitalWrite(ledPin, !inv);
}
void leds::tick()
{
if(state && ((curMS + onMS) < millis())){
state = false;
if(inv)
analogWrite(ledPin, 1);
else
analogWrite(ledPin, 0);
//digitalWrite(ledPin, inv);
}
}

337
ESP_MidRoom/src/main.cpp Normal file
View File

@@ -0,0 +1,337 @@
#include <main.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <leds.h>
#define R_LED (13)
#define G_LED (12)
#define B_LED (0)
#define MOV_SENS (16)
#define P_SENS (14)
bool meas = false;
short minCnt;
bool send_move = false;
int old_mov = 0;
int adc = 0;
int lastADC = 0;
unsigned long cRun;
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
void connectToWifi();
void connectToMqtt();
void onWifiConnect(const WiFiEventStationModeGotIP& event);
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event);
void onMqttConnect(bool sessionPresent);
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason);
void onMqttSubscribe(uint16_t packetId, uint8_t qos);
void onMqttUnsubscribe(uint16_t packetId);
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total);
void onMqttPublish(uint16_t packetId);
//leds b_led(B_LED);
leds g_led(G_LED, 100);
//leds r_led(R_LED, 100);
void setup() {
Serial.begin(9600, SERIAL_8N1);
Serial1.begin(9600);
Serial1.println("Booting"); // "Загрузка"
WiFi.mode(WIFI_STA);
WiFi.hostname("MidRoom");
ArduinoOTA.onStart([]() {
//Serial1.println("Start Update"); // "Начало OTA-апдейта"
});
ArduinoOTA.onEnd([]() {
//Serial1.println("\nEnd Update"); // "Завершение OTA-апдейта"
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
////Serial1.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
// //Serial1.printf("Error[%u]: ", error);
// if (error == OTA_AUTH_ERROR) //Serial1.println("Auth Failed");
// // "Ошибка при аутентификации"
// else if (error == OTA_BEGIN_ERROR) //Serial1.println("Begin Failed");
// // "Ошибка при начале OTA-апдейта"
// else if (error == OTA_CONNECT_ERROR) //Serial1.println("Connect Failed");
// // "Ошибка при подключении"
// else if (error == OTA_RECEIVE_ERROR) //Serial1.println("Receive Failed");
// // "Ошибка при получении данных"
// else if (error == OTA_END_ERROR) //Serial1.println("End Failed");
// // "Ошибка при завершении OTA-апдейта"
});
ArduinoOTA.begin();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
pinMode(MOV_SENS, INPUT_PULLUP);
pinMode(P_SENS, OUTPUT);
pinMode(R_LED, OUTPUT);
pinMode(G_LED, OUTPUT);
pinMode(B_LED, OUTPUT);
//analogWriteRange(100);
digitalWrite(P_SENS, HIGH);
digitalWrite(B_LED, HIGH);
digitalWrite(R_LED, HIGH);
Serial1.println(F("Begin MH-Z19"));
for(int i = 0; i < 5; i++){
Serial1.print('.');
delay(1000);
}
Serial1.println();
mhz19.begin(Serial);
//char myVersion[4];
//mhz19.getVersion(myVersion);
// //Serial1.print("\nFirmware Version: ");
// for(byte i = 0; i < 4; i++)
// {
// //Serial1.print(myVersion[i]);
// if(i == 1)
// //Serial1.print(".");
// }
// //Serial1.println("");
// //Serial1.print("Range: ");
// //Serial1.println(mhz19.getRange());
// //Serial1.print("Background CO2: ");
// //Serial1.println(mhz19.getBackgroundCO2());
// //Serial1.print("Temperature Cal: ");
// //Serial1.println(mhz19.getTempAdjustment());
// //Serial1.print("ABC Status: "); mhz19.getABC() ? //Serial1.println("ON") : //Serial1.println("OFF");
//Serial1.println(F("End Begin MH-Z19"));
Wire.begin();
Serial1.println(F("Begin BME"));
bool status = bme.begin(BME280_ADDRESS_ALTERNATE);
if (!status) {
Serial1.println(F("Could not find a valid BME280 sensor, check wiring, address, sensor ID!"));
}
else{
delay(100);
p = bme.readPressure();
t = bme.readTemperature();
h = bme.readHumidity();
Serial1.print(F("T: "));
Serial1.print(t);
Serial1.print(F("\tH: "));
Serial1.print(h);
Serial1.print(F("\tP: "));
Serial1.println(p);
}
connectToWifi();
cRun = millis();
Serial1.println(F("Start Loop"));
//(R_LED, HIGH);
}
void loop() {
float pt, tt, ht;
char v[11];
static int stDelay = 0;
ArduinoOTA.handle();
g_led.tick();
//r_led.tick();
if (digitalRead(MOV_SENS) != old_mov){
old_mov = digitalRead(MOV_SENS);
Serial1.println(F("Change mov detected"));
mqttClient.publish("/home/midroom/move", 1, false, old_mov ? "1" : "0");
}
if(cRun + 999 < millis()){
cRun = millis();
//if(mqttClient.connected()) digitalWrite(R_LED, LOW); else digitalWrite(R_LED, HIGH);
adc = analogRead(A0);
Serial1.print(F("ADC: "));Serial1.println(adc);
Serial1.print(F("MQTT: "));Serial1.println(mqttClient.connected());
if(abs(adc - lastADC) > 50){
lastADC = adc;
itoa(adc, v, 10);
mqttClient.publish("/home/midroom/light", 1, false, v);
}
if(meas){
//Serial1.println(adc);
Serial1.println("Measure");
pt = bme.readPressure();
tt = bme.readTemperature();
ht = bme.readHumidity();
Serial1.print(F("T: "));
Serial1.print(tt);
Serial1.print(F("\tH: "));
Serial1.print(ht);
Serial1.print(F("\tP: "));
Serial1.println(pt);
if(!isnan(pt))
p += (pt - p) / 60.0f ;
else
{
Serial1.println(F("Error BME"));
}
if(!isnan(tt))
t += (tt - t) / 30.0f ;
if(!isnan(ht))
h += (ht - h) / 30.0f ;
digitalWrite(P_SENS, LOW);
meas = false;
}
else{
if(minCnt % 5 == 0){
co2 = mhz19.getCO2();
Serial1.print("CO2: ");
Serial1.println(co2);
digitalWrite(P_SENS, HIGH);
bme.begin(BME280_ADDRESS_ALTERNATE);
meas = true;
}
}
if(++minCnt == 60){
minCnt = 0;
if(mqttClient.connected()){
g_led.start();
//r_led.start();
//Serial1.println("Begin Publish");
dtostrf(t, 5, 1,v);
mqttClient.publish("/home/midroom/temp", 0, false, v);
//Serial1.println("Publish1");
dtostrf(h, 5, 1,v);
mqttClient.publish("/home/midroom/humid", 0, false, v);
//Serial1.println("Publish2");
if(firstRun){
stDelay++;
if(stDelay > 3) firstRun = false;
}
if(!firstRun && (mhz19.errorCode == RESULT_OK)){
itoa(co2, v, 10);
mqttClient.publish("/home/midroom/co2", 0, false, v);
//Serial1.println("Publish3");
}
}
}
else if(minCnt % 10 == 0){
itoa(millis(), v, 10);
if(mqttClient.connected()){
mqttClient.publish("/home/midroom/millis", 0, false, v);
dtostrf(t, 5, 1,v);
mqttClient.publish("/home/midroom/temp", 0, false, v);
//Serial1.println("Publish1");
dtostrf(h, 5, 1,v);
mqttClient.publish("/home/midroom/humid", 0, false, v);
g_led.start();
}
}
}
}
void connectToWifi() {
Serial1.println(F("Connecting to Wi-Fi..."));
//Serial1.flush();
WiFi.begin(ssid, password);
}
void connectToMqtt() {
Serial1.println(F("Connecting to MQTT..."));
//Serial1.flush();
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial1.println(F("Connected to Wi-Fi."));
Serial1.print(F("IP: "));
//Serial1.flush();
Serial1.println(WiFi.localIP());
digitalWrite(R_LED, LOW);
connectToMqtt();
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial1.println(F("Disconnected from Wi-Fi."));
//Serial1.flush();
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
digitalWrite(R_LED, HIGH);
}
void onMqttConnect(bool sessionPresent) {
Serial1.println(F("Connected to MQTT."));
Serial1.print(F("Session present: "));
//Serial1.flush();
Serial1.println(sessionPresent);
//digitalWrite(B_LED, HIGH);
//digitalWrite(R_LED, LOW);
//uint16_t packetIdSub =
// //Serial1.print("Subscribing Lamp1, packetId: ");
// //Serial1.println(packetIdSub);
//packetIdSub = mqttClient.subscribe("/home/kor/lamp2_set", 1);
////Serial1.print("Subscribing Lamp2, packetId: ");
////Serial1.println(packetIdSub);
////Serial1.println("Publishing at Lamp 1");
//mqttClient.publish("/home/kor/lamp2", 1, false, lStat2 ? "1" : "0");
////Serial1.println("Publishing at Lamp 2");
digitalWrite(B_LED, LOW);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
Serial1.println("Disconnected from MQTT.");
//digitalWrite(B_LED, LOW);
//digitalWrite(R_LED, HIGH);
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(B_LED, HIGH);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
// //Serial1.println("Subscribe acknowledged.");
// //Serial1.print(" packetId: ");
// //Serial1.println(packetId);
// //Serial1.print(" qos: ");
// //Serial1.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
// //Serial1.println("Unsubscribe acknowledged.");
// //Serial1.print(" packetId: ");
// //Serial1.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
if(strcmp(topic, "/home/kor/lamp1_set") == 0){
}
}
void onMqttPublish(uint16_t packetId) {
//Serial1.println("Publish acknowledged.");
//Serial1.print(" packetId: ");
//Serial1.println(packetId);
//g_led.start();
}

11
ESP_MidRoom/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
GateWay/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
GateWay/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
GateWay/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
GateWay/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

5
GateWay/include/mys.h Normal file
View File

@@ -0,0 +1,5 @@
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_RF24_PA_LEVEL (RF24_PA_MAX)
#define MY_RF24_CHANNEL (15)
#define MY_RF24_DATARATE (RF24_250KBPS)

46
GateWay/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

17
GateWay/platformio.ini Normal file
View File

@@ -0,0 +1,17 @@
;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
monitor_speed = 9600
upload_protocol = espota
upload_port = 192.168.1.6

141
GateWay/src/main.cpp Normal file
View File

@@ -0,0 +1,141 @@
#include <Arduino.h>
/* * LED purposes:
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
* - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or receive crc error
*
*/
#define MY_DEBUG
#define MY_BAUD_RATE 9600
#define MY_RADIO_RF24
#define MY_GATEWAY_ESP8266
// #define MY_DISABLED_SERIAL
// #define MY_SPLASH_SCREEN_DISABLED
#define MY_RF24_PA_LEVEL (RF24_PA_MAX)
#define MY_RF24_CHANNEL (15)
#define MY_RF24_DATARATE (RF24_250KBPS)
#define MY_WIFI_SSID "wf-home"
#define MY_WIFI_PASSWORD "0ndthnrf"
#define MY_HOSTNAME "ESP8266_GW"
#define MY_PORT 5003
// How many clients should be able to connect to this gateway (default 1)
#define MY_GATEWAY_MAX_CLIENTS 12
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN D3 // Error led pin
#define MY_DEFAULT_RX_LED_PIN D4 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 1 // the PCB, on board LED
#define MY_WITH_LEDS_BLINKING_INVERSE
#define MY_RF24_CE_PIN D0
#include <ArduinoOTA.h>
#include <MySensors.h>
#include "SdsDustSensor.h"
int rxPin = D1;
int txPin = D2;
SdsDustSensor sds(rxPin, txPin);
unsigned long cRun;
int cSec = 0;
#define CHILD_ID_25 0
#define CHILD_ID_10 1
MyMessage msg25(CHILD_ID_25, V_VAR1);
MyMessage msg10(CHILD_ID_10, V_VAR2);
void setup()
{
WiFi.begin(MY_WIFI_SSID, MY_WIFI_PASSWORD);
if(WiFi.waitForConnectResult() == WL_CONNECTED){
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(MY_WIFI_SSID);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ArduinoOTA.onStart([]() {
Serial.println("ArduinoOTA start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nArduinoOTA end");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA 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");
} 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");
}
});
ArduinoOTA.begin();
sds.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);
cRun = millis();
}
void presentation()
{
sendSketchInfo("GateWayDust", "2.0");
present(CHILD_ID_25, S_AIR_QUALITY, "Dust 2.5");
wait(50);
present(CHILD_ID_10, S_AIR_QUALITY, "Dust 10");
}
void loop()
{
// Send locally attached sensors data here
ArduinoOTA.handle();
if(cRun + 1000 < millis()){
cRun = millis();
PmResult pm = sds.readPm();
cSec++;
if (pm.isOk()) {
// Serial.print(cSec); Serial.print("\t");
// Serial.print("PM2.5 = ");
// Serial.print(pm.pm25);
// Serial.print(", PM10 = ");
// Serial.println(pm.pm10);
// // if you want to just print the measured values, you can use toString() method as well
// Serial.println(pm.toString());
send(msg25.set(pm.pm25, 1));
wait(100);
send(msg10.set(pm.pm10, 1));
cSec = 0;
//} else {
// // notice that loop delay is set to 5s (sensor sends data every 3 minutes) and some reads are not available
// Serial.print(cSec); Serial.print("\t");
// Serial.print("Could not read values from sensor, reason: ");
// Serial.println(pm.statusToString());
}
}
}

11
GateWay/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
I2C Scan/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
I2C Scan/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
I2C Scan/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
I2C Scan/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

46
I2C Scan/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

24
I2C Scan/platformio.ini Normal file
View File

@@ -0,0 +1,24 @@
;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
[platformio]
default_envs = nano
[env:uno]
platform = atmelavr
board = uno
framework = arduino
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
[env:nano]
platform = atmelavr
board = nanoatmega328
framework = arduino

54
I2C Scan/src/main.cpp Normal file
View File

@@ -0,0 +1,54 @@
#include <Arduino.h>
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
/*#undef PIN_WIRE_SDA
#undef PIN_WIRE_SCL
#define PIN_WIRE_SCL D1
#define PIN_WIRE_SDA D2*/
#include <Wire.h>
void setup() {
Serial.begin (9600);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
//#undef SCL
//#undef SDA
Serial.print("SCL=");Serial.println (SCL);
Serial.print("SDA=");Serial.println (SDA);
Serial.print("PWSCL=");Serial.println (PIN_WIRE_SCL);
Serial.print("PWSDA=");Serial.println (PIN_WIRE_SDA);
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
/*#define SCL 5
#define SDA 4*/
Wire.begin();
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 (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}

11
I2C Scan/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
KuhLight_ESP/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
KuhLight_ESP/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
KuhLight_ESP/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View File

@@ -0,0 +1,39 @@
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

46
KuhLight_ESP/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

View File

@@ -0,0 +1,18 @@
; 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:esp07]
platform = espressif8266
board = esp07
framework = arduino
board_build.f_cpu = 26000000L
board_build.ldscript = eagle.flash.1m.ld
upload_protocol = espota
upload_port = 192.168.1.135

191
KuhLight_ESP/src/main.cpp Normal file
View File

@@ -0,0 +1,191 @@
#include <Arduino.h>
//#include <ESP_EEPROM.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
#define LED_WF (12)
#define LED_MQ (13)
#define LED_WRK (14)
#define SENS (4)
#define LAMP (5)
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
unsigned long cRun = 0;
unsigned long lastSense;
uint16_t nSec = 0;
uint8_t lamp, lampP;
uint8_t light;
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial.println("Connected to Wi-Fi.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
connectToMqtt();
digitalWrite(LED_WF, HIGH);
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial.println("Disconnected from Wi-Fi.");
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
digitalWrite(LED_WF, LOW);
}
void onMqttConnect(bool sessionPresent) {
Serial.println("Connected to MQTT.");
Serial.print("Session present: ");
Serial.println(sessionPresent);
mqttClient.subscribe("/home/kuh/lighttbl_set", 1);
mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0");
digitalWrite(LED_MQ, HIGH);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
//Serial.println("Disconnected from MQTT.");
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(LED_MQ, LOW);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
Serial.println("Subscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
Serial.print(" qos: ");
Serial.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
Serial.println("Unsubscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
if(strcmp(topic, "/home/kuh/lighttbl_set") == 0){
light = atoi(payload);
digitalWrite(LAMP, light);
mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0");
}
}
void onMqttPublish(uint16_t packetId) {
Serial.println("Publish acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void setup() {
Serial.begin(9600);
Serial.println("Begin");
WiFi.mode(WIFI_STA);
WiFi.hostname("KuhLight");
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();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
// EEPROM.begin(16);
// EEPROM.get(0, lamp);
pinMode(LAMP, OUTPUT);
pinMode(LED_WF, OUTPUT);
pinMode(LED_MQ, OUTPUT);
pinMode(LED_WRK, OUTPUT);
pinMode(SENS, INPUT);
digitalWrite(LED_WF, LOW);
digitalWrite(LED_MQ, LOW);
digitalWrite(LED_WRK, LOW);
Serial.println("Connect to WiFi");
connectToWifi();
lastSense = millis();
light = false;
Serial.println("Loop");
}
void loop() {
static bool led_wrk = false;
ArduinoOTA.handle();
if(digitalRead(SENS) == 0){
if(lastSense + 3000 < millis()){
lastSense = millis();
light = !light;
digitalWrite(LAMP, light);
mqttClient.publish("/home/kuh/lighttbl", 1, false, light ? "1" : "0");
Serial.println("Change state");
Serial.println(light);
}
}
if(cRun + 999 < millis()){
cRun = millis();
nSec++;
led_wrk = !led_wrk;
digitalWrite(LED_WRK, led_wrk);
if(nSec > 59){
if(mqttClient.connected()){
char v[11];
itoa(millis(), v, 10);
mqttClient.publish("/home/kuh/ltblmillis", 1, false, v);
Serial.print("Millis: ");
Serial.println(millis());
}
nSec = 0;
}
}
}

11
KuhLight_ESP/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

70
MYS_Home.code-workspace Normal file
View File

@@ -0,0 +1,70 @@
{
"folders": [
{
"path": "esp8266-KUH"
},
{
"name": "I2C Scan",
"path": "I2C Scan"
},
{
"name": "ESP12",
"path": "D:\\Projects\\Arduino\\ESP12"
},
{
"name": "VT_ESP8266",
"path": "VT_ESP8266"
},
{
"name": "MainDoor",
"path": "MainDoor"
},
{
"path": "Sw_MidlRoom"
},
{
"path": "Sw_BigRoom"
},
{
"name": "ESP12SmallRoom",
"path": "ESP12SmallRoom"
},
{
"path": "Sw_Koridor"
},
{
"path": "Sw_SmallRoom"
},
{
"path": "ESP_BigRoom"
},
{
"path": "ESP_MidRoom"
},
{
"name": "KuhLight_ESP",
"path": "KuhLight_ESP"
},
{
"path": "ESP_Kor"
},
{
"path": "ESP_Electro"
}
],
"settings": {
"terminal.integrated.env.windows": {
"PATH": "C:\\Users\\Lexa\\.platformio\\penv\\Scripts;C:\\Users\\Lexa\\.platformio\\penv;C:\\Python37\\Scripts\\;C:\\Python37\\;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\AMD\\ATI.ACE\\Core-Static;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\TortoiseSVN\\bin;C:\\Users\\Lexa\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Python37\\Scripts\\;C:\\Python37\\;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\AMD\\ATI.ACE\\Core-Static;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Microsoft\\Web Platform Installer\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\TortoiseSVN\\bin;C:\\Users\\Lexa\\AppData\\Local\\Microsoft\\WindowsApps;",
"PLATFORMIO_CALLER": "vscode"
},
"files.associations": {
"*.tcc": "cpp",
"list": "cpp",
"string": "cpp",
"vector": "cpp",
"memory": "cpp",
"random": "cpp",
"initializer_list": "cpp"
}
}
}

5
MainDoor/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
MainDoor/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
MainDoor/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
MainDoor/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

19
MainDoor/include/leds.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef __LEDS_H__
#define __LEDS_H__
#include <Arduino.h>
class leds
{
private:
int ledPin;
bool inv, state;
int onMS;
unsigned long curMS;
public:
leds(int ledPin, int onms = 300, bool inverse = false);
//~leds();
void start();
void tick();
};
#endif

46
MainDoor/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

19
MainDoor/platformio.ini Normal file
View File

@@ -0,0 +1,19 @@
; 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:nano]
platform = espressif8266
board = nodemcuv2
framework = arduino
board_build.f_cpu = 26000000L
board_build.ldscript = eagle.flash.1m.ld
;board_build.flash_mode = dout
upload_protocol = espota
upload_port = 192.168.1.133

24
MainDoor/src/leds.cpp Normal file
View File

@@ -0,0 +1,24 @@
#include <leds.h>
leds::leds(int pinLED, int onms, bool inverse)
{
ledPin = pinLED;
inv = inverse;
onMS = onms;
state = false;
}
void leds::start()
{
curMS = millis();
state = true;
digitalWrite(ledPin, !inv);
}
void leds::tick()
{
if(state && ((curMS + onMS) < millis())){
state = false;
digitalWrite(ledPin, inv);
}
}

342
MainDoor/src/main.cpp Normal file
View File

@@ -0,0 +1,342 @@
#include <Arduino.h>
//#include <ESP_EEPROM.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <Wire.h>
#include <PCF8574.h>
#include <leds.h>
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
#define L_TOP (2)
#define L_INT (3)
#define L_DOWN (0)
#define L_SMALL (1)
#define DOOR (4)
#define L_WIFI (2) //On board blue
#define L_WIFI2 (14) //Green
#define L_MQTT (13) //Blue
#define L_MSG (12) //Red
unsigned long cRun = 0;
unsigned long l_run;
uint8_t tP, iP, dP, sP, door, doorP;
//uint16_t timeT, timeI, timeD, timeS;
//uint16_t timeTt, timeIt, timeDt, timeSt;
// uint16_t timeAlm, timeOpen;
// bool doorSent, lockSent;
uint16_t nSec = 0;
leds r_led(L_MSG);
uint8_t pcfreg, opcfreg;
PCF8574 pcf(0x3F);
bool l_m = false;
void connectToWifi() {
Serial.println("Connecting to Wi-Fi...");
WiFi.begin(ssid, password);
}
void connectToMqtt() {
Serial.println("Connecting to MQTT...");
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
Serial.println("Connected to Wi-Fi.");
Serial.print("IP: ");
Serial.println(WiFi.localIP());
digitalWrite(L_WIFI, HIGH);
digitalWrite(L_WIFI2, LOW);
connectToMqtt();
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
Serial.println("Disconnected from Wi-Fi.");
digitalWrite(L_WIFI, LOW);
digitalWrite(L_WIFI2, HIGH);
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
}
void onMqttConnect(bool sessionPresent) {
Serial.println("Connected to MQTT.");
Serial.print("Session present: ");
Serial.println(sessionPresent);
//uint16_t packetIdSub =
//mqttClient.subscribe("/home/kor/doortimeout_set", 1);
mqttClient.publish("/home/kor/locker_top", 1, false, tP ? "0" : "1");
mqttClient.publish("/home/kor/locker_int", 1, false, iP ? "0" : "1");
mqttClient.publish("/home/kor/locker_down", 1, false, dP ? "0" : "1");
mqttClient.publish("/home/kor/locker_small", 1, false, sP ? "0" : "1");
mqttClient.publish("/home/kor/door", 1, false, doorP ? "0" : "1");
//mqttClient.publish("/home/kor/doorlocker", 1, false, sP || dP || iP || tP ? "1" : "0");
/*char v[7];
itoa(timeAlm, v, 10);
mqttClient.publish("/home/kor/doortimeout", 1, false, v);*/
//digitalWrite(L_WIFI2, LOW);
digitalWrite(L_MQTT, LOW);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
//Serial.println("Disconnected from MQTT.");
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(L_MQTT, HIGH);
//if(WiFi.isConnected())
// digitalWrite(L_WIFI2, HIGH);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
Serial.println("Subscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
Serial.print(" qos: ");
Serial.println(qos);
}
void onMqttUnsubscribe(uint16_t packetId) {
Serial.println("Unsubscribe acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
/* if(strcmp(topic, "/home/kor/doortimeout_set") == 0){
char v[7];
timeAlm = atoi(payload);
EEPROM.put(0, timeAlm);
EEPROM.commit();
itoa(timeAlm, v, 10);
mqttClient.publish("/home/kor/doortimeout", 0, false, v);
Serial.print("New Timeout: ");
Serial.println(timeAlm);
}*/
}
void onMqttPublish(uint16_t packetId) {
Serial.println("Publish acknowledged.");
Serial.print(" packetId: ");
Serial.println(packetId);
}
void setup() {
Serial.begin(9600);
Serial.println("Begin");
WiFi.mode(WIFI_STA);
WiFi.hostname("Door-Koridor");
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();
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
Wire.begin();
// 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);
if(Wire.endTransmission() == 0) Serial.println("PCF Found");
else Serial.println("PCF Not Found");
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_WIFI2, OUTPUT);
pinMode(L_MQTT, OUTPUT);
pinMode(L_MSG, OUTPUT);
digitalWrite(L_MQTT, HIGH);
digitalWrite(L_WIFI, HIGH);
uint8_t pcfreg = pcf.read8();
tP = pcfreg & 0x1;
iP = (pcfreg >> L_INT) & 0x1;
dP = (pcfreg >> L_DOWN) & 0x1;
sP = (pcfreg >> L_SMALL) & 0x1;
doorP = (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");
connectToWifi();
Serial.println("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);
uint8_t tC, iC, dC, sC;
char v[10];
//door = digitalRead(DOOR);
if(l_m && (l_run + 100) < millis()){
analogWrite(L_MSG, 0);
l_m = false;
}
//r_led.tick();
ArduinoOTA.handle();
if(cRun + 99 < millis()){
cRun = millis();
pcfreg = pcf.read8();
tC = (pcfreg >> L_TOP) & 0x1;
iC = (pcfreg >> L_INT) & 0x1;
dC = (pcfreg >> L_DOWN) & 0x1;
sC = (pcfreg >> L_SMALL) & 0x1;
door = (pcfreg >> DOOR) & 0x1;
if(opcfreg != pcfreg){
itoa(pcfreg, v, 2);
mqttClient.publish("/home/kor/pcf", 1, false, v);
opcfreg = pcfreg;
}
if(tC != tP){
Serial.println("Top Changed");
if(mqttClient.connected()){
mqttClient.publish("/home/kor/locker_top", 1, false, tC ? "0" : "1");
}
tP = tC;
}
if(iC != iP){
if(mqttClient.connected()){
mqttClient.publish("/home/kor/locker_int", 1, false, iC ? "0" : "1");
}
iP = iC;
}
if(dC != dP){
if(mqttClient.connected()){
mqttClient.publish("/home/kor/locker_down", 1, false, dC ? "0" : "1");
}
dP = dC;
}
if(sC != sP){
if(mqttClient.connected()){
mqttClient.publish("/home/kor/locker_small", 1, false, sC ? "0" : "1");
}
sP = sC;
}
if(door != doorP){
if(mqttClient.connected()){
mqttClient.publish("/home/kor/door", 1, false, door ? "0" : "1");
}
doorP = door;
}
nSec++;
// if(nSec % 10 == 0){
// char v[11];
// itoa(pcfreg, v, 2);
// if(mqttClient.connected())
// mqttClient.publish("/home/test/pcfreg", 0, false, v);
// }
if(nSec > 99){
if(mqttClient.connected()){
char v[11];
itoa(millis(), v, 10);
analogWrite(L_MSG, 1);
l_run = millis();
l_m = true;
//r_led.start();
mqttClient.publish("/home/kor/doormillis", 1, false, v);
Serial.print("Millis: ");
Serial.println(millis());
}
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("/home/kor/doorlong", 1, false, "1");
doorSent = true;
}
else{ //Not closed locker
r_led.start();
mqttClient.publish("/home/kor/doorlocker", 1, false, "0");
lockSent = true;
}
}
}
}
else{
timeOpen = 0;
if(doorSent == true){
doorSent = false;
if(mqttClient.connected())
r_led.start();
mqttClient.publish("/home/kor/doorlong", 1, false, "0");
}
if(lockSent == true){
lockSent = false;
if(mqttClient.connected())
r_led.start();
mqttClient.publish("/home/kor/doorlocker", 1, false, "1");
}
}*/
}
}

11
MainDoor/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
Sw_BigRoom/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
Sw_BigRoom/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
Sw_BigRoom/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
Sw_BigRoom/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

46
Sw_BigRoom/lib/README Normal file
View File

@@ -0,0 +1,46 @@
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

17
Sw_BigRoom/platformio.ini Normal file
View File

@@ -0,0 +1,17 @@
; 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
board_build.ldscript = eagle.flash.2m.ld
upload_protocol = espota
upload_port = 192.168.1.129

395
Sw_BigRoom/src/main.cpp Normal file
View File

@@ -0,0 +1,395 @@
// #include <Arduino.h>
// #include <ESP8266WiFi.h>
// #include <ESP8266mDNS.h>
// #include <WiFiUdp.h>
// #include <ArduinoOTA.h>
// #include <Bounce2.h>
// #include <PubSubClient.h>
// #include <ESP_EEPROM.h>
// // замените значения в этих константах на те,
// // что соответствуют вашей сети:
// const char* ssid = "wf-home";
// const char* password = "0ndthnrf";
// const char* mqtt_server = "192.168.1.250";
// //unsigned long int cRun;
// bool lStat1;
// bool lStat2;
// #define B_LED 16
// //bool led = false;
// Bounce l1 = Bounce();
// Bounce l2 = Bounce();
// WiFiClient espClient;
// PubSubClient client(espClient);
// void callback(char* topic, byte* payload, unsigned int length) {
// Serial.print("Message arrived [");
// Serial.print(topic);
// Serial.print("] ");
// for (unsigned int i = 0; i < length; i++) {
// Serial.print((char)payload[i]);
// }
// Serial.println();
// if(strcmp(topic, "/home/bigroom/lamp1_set") == 0){
// if ((char)payload[0] == '1') lStat1 = true;
// else lStat1 = false;
// EEPROM.put(0, lStat1);
// EEPROM.commit();
// Serial.print("Lamp 1: ");
// Serial.println(lStat1);
// if (client.connected())
// client.publish("/home/bigroom/lamp1", lStat1 ? "1" : "0");
// //setLamp(0);
// }
// if(strcmp(topic, "/home/bigroom/lamp2_set") == 0){
// if ((char)payload[0] == '1') lStat2 = true;
// else lStat2 = false;
// //setLamp(1);
// EEPROM.put(1, lStat2);
// EEPROM.commit();
// Serial.print("Lamp 2: ");
// Serial.println(lStat2);
// if (client.connected())
// client.publish("/home/bigroom/lamp2", lStat2 ? "1" : "0");
// }
// // Switch on the LED if an 1 was received as first character
// //if ((char)payload[0] == '1') {
// //digitalWrite(LED_BUILTIN, LOW); // Turn the LED on (Note that LOW is the voltage level
// // but actually the LED is on; this is because
// // it is active low on the ESP-01)
// //} else {
// //digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
// //}
// }
// void reconnect() {
// // Loop until we're reconnected
// int cntConn = 0;
// int cntConnW = 0;
// while (!client.connected() && cntConn < 5) {
// if(!WiFi.isConnected()){
// WiFi.disconnect();
// WiFi.begin(ssid, password);
// while ((WiFi.waitForConnectResult() != WL_CONNECTED) && cntConn < 5) {
// Serial.println("Connection Failed! Rebooting...");
// // "Соединиться не удалось! Перезагрузка..."
// delay(1000);
// cntConn++;
// }
// }
// Serial.print("Attempting MQTT connection...");
// // Create a random client ID
// String clientId = "SwitchBigRoom";
// //clientId += String(random(0xffff), HEX);
// // Attempt to connect
// if (client.connect(clientId.c_str())) {
// Serial.println("connected");
// // Once connected, publish an announcement...
// //client.publish("outTopic", "hello world");
// // ... and resubscribe
// client.subscribe("/home/bigroom/lamp1_set");
// client.subscribe("/home/bigroom/lamp2_set");
// digitalWrite(B_LED, LOW);
// } else {
// Serial.print("failed, rc=");
// Serial.print(client.state());
// Serial.println(" try again in 5 seconds");
// digitalWrite(B_LED, HIGH);
// // Wait 5 seconds before retrying
// //delay(5000);
// }
// cntConn++;
// }
// }
// void setup() {
// Serial.begin(9600);
// Serial.println("Booting"); // "Загрузка"
// WiFi.mode(WIFI_STA);
// WiFi.hostname("SW-BigRoom");
// WiFi.begin(ssid, password);
// int cntConn = 0;
// while ((WiFi.waitForConnectResult() != WL_CONNECTED) && cntConn < 5) {
// Serial.println("Connection Failed! Rebooting...");
// // "Соединиться не удалось! Перезагрузка..."
// delay(1000);
// cntConn++;
// ESP.restart();
// }
// // строчка для номера порта по умолчанию
// // можно вписать «8266»:
// // ArduinoOTA.setPort(8266);
// // строчка для названия хоста по умолчанию;
// // можно вписать «esp8266-[ID чипа]»:
// // ArduinoOTA.setHostname("myesp8266");
// // строчка для аутентификации
// // (по умолчанию никакой аутентификации не будет):
// // ArduinoOTA.setPassword((const char *)"123");
// 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();
// Serial.println("Ready"); // "Готово"
// Serial.print("IP address: "); // "IP-адрес: "
// Serial.println(WiFi.localIP());
// //pinMode(0, INPUT_PULLUP);
// //l1.attach(0);
// pinMode(B_LED, OUTPUT);
// pinMode(4, OUTPUT);
// pinMode(13, OUTPUT);
// pinMode(14, INPUT);
// l1.attach(14);
// pinMode(12, INPUT);
// l2.attach(12);
// lStat1 = false;
// lStat2 = false;
// client.setServer(mqtt_server, 1883);
// client.setCallback(callback);
// EEPROM.begin(16);
// EEPROM.get(0, lStat1);
// EEPROM.get(1, lStat2);
// //cRun = millis();
// }
// void loop() {
// ArduinoOTA.handle();
// digitalWrite(4, lStat1);
// digitalWrite(13, lStat2);
// if (!client.connected()) {
// reconnect();
// }
// client.loop();
// l1.update();
// l2.update();
// if(l1.fell()){
// lStat1 = !lStat1;
// //digitalWrite(4, lStat1);
// EEPROM.put(0, lStat1);
// EEPROM.commit();
// Serial.print("Lamp 1: ");
// Serial.println(lStat1);
// if (client.connected())
// client.publish("/home/bigroom/lamp1", String(lStat1).c_str());
// }
// if(l2.fell()){
// lStat2 = !lStat2;
// //digitalWrite(13, lStat2);
// EEPROM.put(1, lStat2);
// EEPROM.commit();
// Serial.print("Lamp 2: ");
// Serial.println(lStat2);
// if (client.connected())
// client.publish("/home/bigroom/lamp2", String(lStat2).c_str());
// }
// // if(cRun + 500 < millis()){
// // digitalWrite(B_LED, led);
// // led = !led;
// // cRun = millis();
// // }
// }
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <Ticker.h>
#include <AsyncMqttClient.h>
#include <ESP_EEPROM.h>
#include <Bounce2.h>
const char* ssid = "wf-home";
const char* password = "0ndthnrf";
const char* mqtt_server = "192.168.1.250";
AsyncMqttClient mqttClient;
Ticker mqttReconnectTimer;
WiFiEventHandler wifiConnectHandler;
WiFiEventHandler wifiDisconnectHandler;
Ticker wifiReconnectTimer;
bool lStat1, oldLStat1;
bool lStat2, oldLStat2;
unsigned long cRun;
#define B_LED (16)
#define R_LED1 (4)
#define R_LED2 (13)
#define BUTT1 (14)
#define BUTT2 (12)
bool led = false;
Bounce l1 = Bounce();
Bounce l2 = Bounce();
void connectToWifi() {
WiFi.begin(ssid, password);
}
void connectToMqtt() {
mqttClient.connect();
}
void onWifiConnect(const WiFiEventStationModeGotIP& event) {
connectToMqtt();
}
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event) {
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
wifiReconnectTimer.once(2, connectToWifi);
}
void onMqttConnect(bool sessionPresent) {
mqttClient.subscribe("/home/bigroom/lamp1_set", 1);
mqttClient.subscribe("/home/bigroom/lamp2_set", 1);
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
digitalWrite(B_LED, LOW);
}
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason) {
if (WiFi.isConnected()) {
mqttReconnectTimer.once(2, connectToMqtt);
}
digitalWrite(B_LED, HIGH);
}
void onMqttSubscribe(uint16_t packetId, uint8_t qos) {
}
void onMqttUnsubscribe(uint16_t packetId) {
}
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
if(strcmp(topic, "/home/bigroom/lamp1_set") == 0){
if ((char)payload[0] == '1') lStat1 = true;
else lStat1 = false;
}
if(strcmp(topic, "/home/bigroom/lamp2_set") == 0){
if ((char)payload[0] == '1') lStat2 = true;
else lStat2 = false;
}
}
void onMqttPublish(uint16_t packetId) {
}
void setup() {
WiFi.mode(WIFI_STA);
WiFi.hostname("SW-BigRoom");
ArduinoOTA.onStart([]() {
});
ArduinoOTA.onEnd([]() {
});
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();
//pinMode(B_LED, FUNCTION_3);
pinMode(B_LED, OUTPUT);
digitalWrite(B_LED, HIGH);
pinMode(R_LED1, OUTPUT);
pinMode(BUTT1, INPUT_PULLUP);
pinMode(R_LED2, OUTPUT);
pinMode(BUTT2, FUNCTION_3);
pinMode(BUTT2, INPUT_PULLUP);
l1.attach(BUTT1);
l2.attach(BUTT2);
EEPROM.begin(16);
EEPROM.get(0, lStat1);
EEPROM.get(1, lStat2);
oldLStat1 = lStat1;
oldLStat2 = lStat2;
// Serial.print("Lamp1: ");
// Serial.println(lStat1);
digitalWrite(R_LED1, lStat1);
digitalWrite(R_LED2, lStat2);
//oldLStat2 = lStat2;
wifiConnectHandler = WiFi.onStationModeGotIP(onWifiConnect);
wifiDisconnectHandler = WiFi.onStationModeDisconnected(onWifiDisconnect);
mqttClient.onConnect(onMqttConnect);
mqttClient.onDisconnect(onMqttDisconnect);
mqttClient.onSubscribe(onMqttSubscribe);
mqttClient.onUnsubscribe(onMqttUnsubscribe);
mqttClient.onMessage(onMqttMessage);
mqttClient.onPublish(onMqttPublish);
mqttClient.setServer(mqtt_server, 1883);
connectToWifi();
cRun = millis();
}
void loop() {
ArduinoOTA.handle();
l1.update();
l2.update();
if(l1.fell()){
lStat1 = !lStat1;
}
if(l2.fell()){
lStat2 = !lStat2;
}
if(lStat1 != oldLStat1){
digitalWrite(R_LED1, lStat1);
oldLStat1 = lStat1;
mqttClient.publish("/home/bigroom/lamp1", 1, false, lStat1 ? "1" : "0");
EEPROM.put(0, lStat1);
EEPROM.commit();
}
if(lStat2 != oldLStat2){
digitalWrite(R_LED2, lStat2);
oldLStat2 = lStat2;
mqttClient.publish("/home/bigroom/lamp2", 1, false, lStat2 ? "1" : "0");
EEPROM.put(1, lStat2);
EEPROM.commit();
}
}

11
Sw_BigRoom/test/README Normal file
View File

@@ -0,0 +1,11 @@
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

5
Sw_Koridor/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

67
Sw_Koridor/.travis.yml Normal file
View File

@@ -0,0 +1,67 @@
# 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
Sw_Koridor/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
Sw_Koridor/include/README Normal file
View File

@@ -0,0 +1,39 @@
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

Some files were not shown because too many files have changed in this diff Show More