mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
First working platformio version
This commit is contained in:
@@ -1,36 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
|
||||||
|
|
||||||
extern void CMD_init();
|
|
||||||
extern void button();
|
|
||||||
extern void buttonSet();
|
|
||||||
extern void buttonChange();
|
|
||||||
extern void pinSet();
|
|
||||||
extern void pinChange();
|
|
||||||
extern void handle_time_init();
|
|
||||||
extern void pwm();
|
|
||||||
extern void switch_();
|
|
||||||
extern void pwmSet();
|
|
||||||
extern void stepper();
|
|
||||||
extern void stepperSet();
|
|
||||||
extern void servo_();
|
|
||||||
extern void servoSet();
|
|
||||||
extern void serialBegin();
|
|
||||||
extern void serialWrite();
|
|
||||||
extern void logging();
|
|
||||||
extern void inputDigit();
|
|
||||||
extern void digitSet();
|
|
||||||
extern void inputTime();
|
|
||||||
extern void button();
|
|
||||||
extern void timeSet();
|
|
||||||
extern void text();
|
|
||||||
extern void textSet();
|
|
||||||
extern void mqttOrderSend();
|
|
||||||
extern void httpOrderSend();
|
|
||||||
extern void firmware();
|
|
||||||
extern void update_firmware();
|
|
||||||
extern void Scenario_init();
|
|
||||||
extern void txtExecution(String file);
|
|
||||||
extern void stringExecution(String str);
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <SPIFFS.h>
|
|
||||||
|
|
||||||
extern void File_system_init();
|
|
||||||
165
include/Global.h
Normal file
165
include/Global.h
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Consts.h"
|
||||||
|
|
||||||
|
// Cmd
|
||||||
|
extern void CMD_init();
|
||||||
|
extern void button();
|
||||||
|
extern void buttonSet();
|
||||||
|
extern void buttonChange();
|
||||||
|
extern void pinSet();
|
||||||
|
extern void pinChange();
|
||||||
|
extern void handle_time_init();
|
||||||
|
extern void pwm();
|
||||||
|
extern void switch_();
|
||||||
|
extern void pwmSet();
|
||||||
|
extern void stepper();
|
||||||
|
extern void stepperSet();
|
||||||
|
extern void servo_();
|
||||||
|
extern void servoSet();
|
||||||
|
extern void serialBegin();
|
||||||
|
extern void serialWrite();
|
||||||
|
extern void logging();
|
||||||
|
extern void inputDigit();
|
||||||
|
extern void digitSet();
|
||||||
|
extern void inputTime();
|
||||||
|
extern void button();
|
||||||
|
extern void timeSet();
|
||||||
|
extern void text();
|
||||||
|
extern void textSet();
|
||||||
|
extern void mqttOrderSend();
|
||||||
|
extern void httpOrderSend();
|
||||||
|
extern void firmware();
|
||||||
|
extern void update_firmware();
|
||||||
|
extern void Scenario_init();
|
||||||
|
extern void txtExecution(String file);
|
||||||
|
extern void stringExecution(String str);
|
||||||
|
|
||||||
|
// FileSystem
|
||||||
|
extern void File_system_init();
|
||||||
|
|
||||||
|
// i2c_bu
|
||||||
|
extern void do_i2c_scanning();
|
||||||
|
extern String i2c_scan();
|
||||||
|
|
||||||
|
// Init
|
||||||
|
extern void All_init();
|
||||||
|
extern void statistics_init();
|
||||||
|
extern void Scenario_init();
|
||||||
|
extern void Device_init();
|
||||||
|
extern void prsets_init();
|
||||||
|
extern void up_time();
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
extern void logging();
|
||||||
|
extern void deleteOldDate(String file, int seted_number_of_lines, String date_to_add);
|
||||||
|
extern void clean_log_date();
|
||||||
|
extern void choose_log_date_and_send();
|
||||||
|
|
||||||
|
// Main
|
||||||
|
void getMemoryLoad(String text);
|
||||||
|
|
||||||
|
extern String jsonReadStr(String& json, String name);
|
||||||
|
extern int jsonReadInt(String& json, String name);
|
||||||
|
extern String jsonWriteInt(String& json, String name, int volume);
|
||||||
|
extern String jsonWriteStr(String& json, String name, String volume);
|
||||||
|
extern void saveConfig();
|
||||||
|
extern String jsonWriteFloat(String& json, String name, float volume);
|
||||||
|
|
||||||
|
extern String getURL(String urls);
|
||||||
|
|
||||||
|
extern String writeFile(String fileName, String strings);
|
||||||
|
extern String readFile(String fileName, size_t len);
|
||||||
|
extern String addFile(String fileName, String strings);
|
||||||
|
|
||||||
|
//STRING
|
||||||
|
extern String selectToMarkerLast(String str, String found);
|
||||||
|
extern String selectToMarker(String str, String found);
|
||||||
|
extern String deleteAfterDelimiter(String str, String found);
|
||||||
|
extern String deleteBeforeDelimiter(String str, String found);
|
||||||
|
extern String deleteBeforeDelimiterTo(String str, String found);
|
||||||
|
|
||||||
|
extern String selectFromMarkerToMarker(String str, String found, int number);
|
||||||
|
|
||||||
|
extern void servo_();
|
||||||
|
extern boolean isDigitStr(String str);
|
||||||
|
extern String jsonWriteStr(String& json, String name, String volume);
|
||||||
|
extern void led_blink(String satus);
|
||||||
|
extern int count(String str, String found);
|
||||||
|
|
||||||
|
|
||||||
|
// Mqtt
|
||||||
|
extern void MQTT_init();
|
||||||
|
extern boolean MQTT_Connecting();
|
||||||
|
extern boolean sendMQTT(String end_of_topik, String data);
|
||||||
|
extern boolean sendCHART(String topik, String data);
|
||||||
|
extern void sendSTATUS(String topik, String state);
|
||||||
|
extern void sendCONTROL(String id, String topik, String state);
|
||||||
|
extern void do_mqtt_connection();
|
||||||
|
extern void handleMQTT();
|
||||||
|
extern String selectFromMarkerToMarker(String str, String found, int number);
|
||||||
|
|
||||||
|
// WiFiUtils
|
||||||
|
extern void WIFI_init();
|
||||||
|
extern void All_init();
|
||||||
|
extern bool StartAPMode();
|
||||||
|
extern void ROUTER_Connecting();
|
||||||
|
|
||||||
|
//Scenario
|
||||||
|
extern void eventGen(String event_name, String number);
|
||||||
|
extern String add_set(String param_name);
|
||||||
|
|
||||||
|
//Sensors
|
||||||
|
extern void sensors_init();
|
||||||
|
|
||||||
|
//Timers
|
||||||
|
extern void Timer_countdown_init();
|
||||||
|
extern void timerStart_();
|
||||||
|
extern void addTimer(String number, String time);
|
||||||
|
extern void timerStop_();
|
||||||
|
extern void delTimer(String number);
|
||||||
|
extern int readTimer(int number);
|
||||||
|
|
||||||
|
//TimeUtils
|
||||||
|
extern void Time_Init();
|
||||||
|
extern int timeToMin(String Time);
|
||||||
|
extern String GetDataDigital();
|
||||||
|
extern String GetDate();
|
||||||
|
extern String GetTimeWOsec();
|
||||||
|
extern String GetTime();
|
||||||
|
extern String GetTimeUnix();
|
||||||
|
extern void reconfigTime();
|
||||||
|
extern void saveConfig();
|
||||||
|
extern String GetTimeUnix();
|
||||||
|
extern void time_check();
|
||||||
|
|
||||||
|
//Upgrade
|
||||||
|
extern void initUpgrade();
|
||||||
|
|
||||||
|
//widget
|
||||||
|
extern void createWidget(String widget_name, String page_name, String page_number, String file, String topic);
|
||||||
|
extern void createWidgetParam(String widget_name, String page_name, String page_number, String file, String topic, String name1, String param1, String name2, String param2, String name3, String param3);
|
||||||
|
extern void choose_widget_and_create(String widget_name, String page_name, String page_number, String type, String topik);
|
||||||
|
extern void createChart(String widget_name, String page_name, String page_number, String file, String topic, String maxCount);
|
||||||
|
|
||||||
|
// Push
|
||||||
|
|
||||||
|
extern void Push_init();
|
||||||
|
|
||||||
|
// UDP
|
||||||
|
extern void UDP_init();
|
||||||
|
extern void do_udp_data_parse();
|
||||||
|
extern void do_mqtt_send_settings_to_udp();
|
||||||
|
// WebServer
|
||||||
|
extern void Web_server_init();
|
||||||
|
|
||||||
|
//iot_firmware
|
||||||
|
extern void not_async_actions();
|
||||||
|
extern void handleCMD_loop();
|
||||||
|
extern void handleButton();
|
||||||
|
extern void handleScenario();
|
||||||
|
extern void handleUdp();
|
||||||
|
extern void do_upgrade_url();
|
||||||
|
extern void do_upgrade();
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
extern void Scenario_init();
|
|
||||||
extern void Device_init();
|
|
||||||
extern void prsets_init();
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern void logging();
|
|
||||||
extern void deleteOldDate(String file, int seted_number_of_lines, String date_to_add);
|
|
||||||
extern void clean_log_date();
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern boolean MQTT_Connecting();
|
|
||||||
extern boolean sendMQTT(String end_of_topik, String data);
|
|
||||||
extern boolean sendCHART(String topik, String data);
|
|
||||||
extern void sendSTATUS(String topik, String state);
|
|
||||||
extern void sendCONTROL(String id, String topik, String state);
|
|
||||||
|
|
||||||
extern void do_mqtt_connection();
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern void eventGen(String event_name, String number);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
void sensors_init();
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
//Strings
|
||||||
// #include <stdafx.h>
|
// #include <stdafx.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -135,4 +136,4 @@ inline void char_array::printinput() {
|
|||||||
inline void char_array::changedefaultsize() {
|
inline void char_array::changedefaultsize() {
|
||||||
printf("Input new default input string size: ");
|
printf("Input new default input string size: ");
|
||||||
scanf("%i", charinput);
|
scanf("%i", charinput);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern int timeToMin(String Time);
|
|
||||||
extern String GetDataDigital();
|
|
||||||
extern String GetDate();
|
|
||||||
extern String GetTimeWOsec();
|
|
||||||
extern String GetTime();
|
|
||||||
extern String GetTimeUnix();
|
|
||||||
extern void reconfigTime();
|
|
||||||
extern void saveConfig();
|
|
||||||
extern String GetTimeUnix();
|
|
||||||
extern void time_check();
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern void Timer_countdown_init();
|
|
||||||
extern void addTimer(String number, String time);
|
|
||||||
extern int readTimer(int number);
|
|
||||||
extern void delTimer(String number);
|
|
||||||
extern void timerStop();
|
|
||||||
extern void delTimer(String number);
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
extern void initUpgrade();
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
extern bool StartAPMode();
|
|
||||||
extern void ROUTER_Connecting();
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern void createWidget(String widget_name, String page_name, String page_number, String file, String topic);
|
|
||||||
extern void createWidgetParam(String widget_name, String page_name, String page_number, String file, String topic, String name1, String param1, String name2, String param2, String name3, String param3);
|
|
||||||
extern void choose_widget_and_create(String widget_name, String page_name, String page_number, String type, String topik);
|
|
||||||
extern void createChart(String widget_name, String page_name, String page_number, String file, String topic, String maxCount);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
extern void do_i2c_scanning();
|
|
||||||
|
|
||||||
extern String i2c_scan();
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
void getMemoryLoad(String text);
|
|
||||||
|
|
||||||
extern String jsonReadStr(String& json, String name);
|
|
||||||
extern int jsonReadInt(String& json, String name);
|
|
||||||
extern String jsonWriteInt(String& json, String name, int volume);
|
|
||||||
extern String jsonWriteStr(String& json, String name, String volume);
|
|
||||||
extern void saveConfig();
|
|
||||||
extern String jsonWriteFloat(String& json, String name, float volume);
|
|
||||||
|
|
||||||
extern String getURL(String urls);
|
|
||||||
|
|
||||||
extern String writeFile(String fileName, String strings);
|
|
||||||
extern String readFile(String fileName, size_t len);
|
|
||||||
extern String addFile(String fileName, String strings);
|
|
||||||
|
|
||||||
extern String selectFromMarkerToMarker(String str, String found, int number);
|
|
||||||
extern String selectToMarker(String str, String found);
|
|
||||||
extern String deleteAfterDelimiter(String str, String found);
|
|
||||||
extern String deleteBeforeDelimiter(String str, String found);
|
|
||||||
extern String deleteBeforeDelimiterTo(String str, String found);
|
|
||||||
|
|
||||||
extern void servo_();
|
|
||||||
extern boolean isDigitStr(String str);
|
|
||||||
extern String jsonWriteStr(String& json, String name, String volume);
|
|
||||||
|
|
||||||
extern void led_blink(String satus);
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "main.h"
|
#include "Global.h"
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
inline void Push_init() {
|
inline void Push_init() {
|
||||||
server.on("/pushingboxDate", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/pushingboxDate", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
|||||||
17
lib/ESPrelay/.gitattributes
vendored
17
lib/ESPrelay/.gitattributes
vendored
@@ -1,17 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
|
|
||||||
# Custom for Visual Studio
|
|
||||||
*.cs diff=csharp
|
|
||||||
|
|
||||||
# Standard to msysgit
|
|
||||||
*.doc diff=astextplain
|
|
||||||
*.DOC diff=astextplain
|
|
||||||
*.docx diff=astextplain
|
|
||||||
*.DOCX diff=astextplain
|
|
||||||
*.dot diff=astextplain
|
|
||||||
*.DOT diff=astextplain
|
|
||||||
*.pdf diff=astextplain
|
|
||||||
*.PDF diff=astextplain
|
|
||||||
*.rtf diff=astextplain
|
|
||||||
*.RTF diff=astextplain
|
|
||||||
@@ -1,215 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2016 TheThings.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
|
|
||||||
Original Maker: Mateo Velez - Metavix for TheThings Inc
|
|
||||||
Modified and Maintened by: Jose Garcia - TheThings Inc
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "TheThingsMQTT.h"
|
|
||||||
|
|
||||||
|
|
||||||
TheThings::TheThings(char* token){
|
|
||||||
initialize(token, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TheThings::TheThings(char* token, char* clientName) {
|
|
||||||
initialize(token, clientName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TheThings::begin(void (*callback)(char*,uint8_t*,unsigned int)) {
|
|
||||||
this->callback = callback;
|
|
||||||
_client.setServer(_server, MQTT_PORT);
|
|
||||||
_client.setCallback(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::add(char* variableLabel, float value) {
|
|
||||||
return add(variableLabel, value, "NULL", "NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::add(char* variableLabel, float value, char *context) {
|
|
||||||
return add(variableLabel, value, context, "NULL");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::add(char* variableLabel, float value, char *context, char *timestamp) {
|
|
||||||
(val+currentValue)->_variableLabel = variableLabel;
|
|
||||||
(val+currentValue)->_value = value;
|
|
||||||
(val+currentValue)->_context = context;
|
|
||||||
(val+currentValue)->_timestamp = timestamp;
|
|
||||||
currentValue++;
|
|
||||||
if (currentValue > MAX_VALUES) {
|
|
||||||
Serial.println(F("You are sending more than the maximum of consecutive variables"));
|
|
||||||
currentValue = MAX_VALUES;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::connected(){
|
|
||||||
return _client.connected();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
char* TheThings::getMac(){
|
|
||||||
// Obtains the MAC of the device
|
|
||||||
Serial.println("entra");
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
char macAddr[18];
|
|
||||||
sprintf(macAddr, "%2X%2X%2X%2X%2X%2X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
||||||
return macAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TheThings::initialize(char* token, char* clientName){
|
|
||||||
_server = SERVER;
|
|
||||||
_token = token;
|
|
||||||
currentValue = 0;
|
|
||||||
val = (Value *)malloc(MAX_VALUES*sizeof(Value));
|
|
||||||
if(clientName!=NULL){
|
|
||||||
_clientName = clientName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::loop() {
|
|
||||||
if (!_client.connected()) {
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
return _client.loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TheThings::reconnect() {
|
|
||||||
while (!_client.connected()) {
|
|
||||||
Serial.print("Attempting MQTT connection...");
|
|
||||||
if (_client.connect(_clientName, _token, NULL)) {
|
|
||||||
Serial.println("connected");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
Serial.print("failed, rc=");
|
|
||||||
Serial.print(_client.state());
|
|
||||||
Serial.println(" try again in 3 seconds");
|
|
||||||
delay(3000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TheThings::setDebug(bool debug){
|
|
||||||
_debug = debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TheThings:: setBroker(char* broker){
|
|
||||||
if (_debug){
|
|
||||||
Serial.println("Broker set for Business Account");
|
|
||||||
}
|
|
||||||
_server = broker;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::subscribe() {
|
|
||||||
char topic[150];
|
|
||||||
sprintf(topic, "%s%s", FIRST_PART_TOPIC, _token);
|
|
||||||
if (!_client.connected()) {
|
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
if (_debug){
|
|
||||||
Serial.println("Subscribed to: ");
|
|
||||||
Serial.println(topic);
|
|
||||||
}
|
|
||||||
return _client.subscribe(topic);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::publish() {
|
|
||||||
|
|
||||||
char topic[150];
|
|
||||||
char payload[500];
|
|
||||||
String str;
|
|
||||||
sprintf(topic, "%s%s", FIRST_PART_TOPIC, _token);
|
|
||||||
sprintf(payload, "[");
|
|
||||||
for (int i = 0; i <= currentValue; ) {
|
|
||||||
str = String((val+i)->_value, 1);
|
|
||||||
sprintf(payload,"%s{\"key\":\"%s\",\"value\":%s",payload,(val+i)->_variableLabel, str.c_str());
|
|
||||||
if ((val+i)->_timestamp != "NULL") {
|
|
||||||
sprintf(payload, "%s, \"timestamp\": %s", payload, (val+i)->_timestamp);
|
|
||||||
}
|
|
||||||
if ((val+i)->_context != "NULL") {
|
|
||||||
sprintf(payload, "%s, \"context\": {%s}", payload, (val+i)->_context);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
if (i >= currentValue) {
|
|
||||||
sprintf(payload, "%s}]", payload);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
sprintf(payload, "%s},", payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (_debug){
|
|
||||||
Serial.println("publishing to TOPIC: ");
|
|
||||||
Serial.println(topic);
|
|
||||||
Serial.print("JSON dict: ");
|
|
||||||
Serial.println(payload);
|
|
||||||
}
|
|
||||||
currentValue = 0;
|
|
||||||
return _client.publish(topic, payload, 512);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool TheThings::wifiConnection(char* ssid, char* pass) {
|
|
||||||
WiFi.begin(ssid, pass);
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
Serial.println(F("WiFi connected"));
|
|
||||||
Serial.println(F("IP address: "));
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
if(_clientName==NULL){
|
|
||||||
_clientName = getMac();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TheThings::wifiConnection2() {
|
|
||||||
WiFiManager wifiManager;
|
|
||||||
wifiManager.setTimeout(180);
|
|
||||||
|
|
||||||
//if(!wifiManager.autoConnect("AutoConnectAP")) {
|
|
||||||
if(!wifiManager.autoConnect()) {
|
|
||||||
Serial.println("failed to connect and hit timeout");
|
|
||||||
delay(3000);
|
|
||||||
ESP.reset();
|
|
||||||
delay(5000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int TheThings::state() {
|
|
||||||
return _client.state();
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
|
|
||||||
#ifndef TheThingsMQTT_H
|
|
||||||
#define TheThingsMQTT_H
|
|
||||||
//#include <ESP8266WiFi.h>
|
|
||||||
#include <PubSubClient.h>
|
|
||||||
#include <WiFiManager.h>
|
|
||||||
|
|
||||||
#define MQTT_PORT 1883
|
|
||||||
#define SERVER "mqtt.thethings.io"
|
|
||||||
#define MAX_VALUES 5
|
|
||||||
#define FIRST_PART_TOPIC "v2/things/"
|
|
||||||
|
|
||||||
#define META_DEBUG Serial
|
|
||||||
|
|
||||||
typedef struct Value {
|
|
||||||
char* _variableLabel;
|
|
||||||
float _value;
|
|
||||||
char* _context;
|
|
||||||
char* _timestamp;
|
|
||||||
} Value;
|
|
||||||
|
|
||||||
class TheThings {
|
|
||||||
private:
|
|
||||||
void (*callback)(char*, uint8_t*, unsigned int);
|
|
||||||
char* getMac();
|
|
||||||
void initialize(char* token, char* clientName);
|
|
||||||
WiFiClient espClient;
|
|
||||||
PubSubClient _client = PubSubClient(espClient);
|
|
||||||
WiFiManager wifiManager;
|
|
||||||
char* _clientName = NULL;
|
|
||||||
bool _debug = false;
|
|
||||||
uint8_t currentValue;
|
|
||||||
char* _password;
|
|
||||||
char* _server;
|
|
||||||
char* _ssid;
|
|
||||||
char* _token;
|
|
||||||
Value* val;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TheThings(char* token);
|
|
||||||
TheThings(char* token, char* clientName);
|
|
||||||
bool add(char* variableLabel, float value);
|
|
||||||
bool add(char* variableLabel, float value, char* context);
|
|
||||||
bool add(char* variableLabel, float value, char* context, char* timestamp);
|
|
||||||
void begin(void (*callback)(char*, uint8_t*, unsigned int));
|
|
||||||
bool connected();
|
|
||||||
bool loop();
|
|
||||||
bool subscribe();
|
|
||||||
bool publish();
|
|
||||||
void setBroker(char* broker);
|
|
||||||
void reconnect();
|
|
||||||
void setDebug(bool debug);
|
|
||||||
bool wifiConnection(char* ssid, char* pass);
|
|
||||||
bool wifiConnection2();
|
|
||||||
int state();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <arduino.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
class Ticker {
|
|
||||||
typedef void (*ticker_callback_t)(bool *);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool is_attached = false;
|
|
||||||
uint32_t period = 0;
|
|
||||||
uint32_t last_tick = 0;
|
|
||||||
ticker_callback_t callback;
|
|
||||||
bool *callback_argument;
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Tick() {
|
|
||||||
if (is_attached && millis() - last_tick >= period) {
|
|
||||||
callback(callback_argument);
|
|
||||||
last_tick = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void detach() {
|
|
||||||
this->is_attached = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename TArg>
|
|
||||||
void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg) {
|
|
||||||
this->period = milliseconds;
|
|
||||||
this->callback = callback;
|
|
||||||
this->callback_argument = arg;
|
|
||||||
this->is_attached = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
|
||||||
#include <Ticker.h>
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void tickerFlagHandle(volatile bool *flag);
|
|
||||||
|
|
||||||
#ifdef _GLIBCXX_FUNCTIONAL
|
|
||||||
typedef std::function<void(void *)> tscallback_t;
|
|
||||||
#else
|
|
||||||
typedef void (*tscallback_t)(void *);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct TickerSchedulerItem {
|
|
||||||
Ticker t;
|
|
||||||
volatile bool flag = false;
|
|
||||||
tscallback_t cb;
|
|
||||||
void *cb_arg;
|
|
||||||
uint32_t period;
|
|
||||||
volatile bool is_used = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TickerScheduler {
|
|
||||||
private:
|
|
||||||
uint8_t size;
|
|
||||||
TickerSchedulerItem *items = NULL;
|
|
||||||
|
|
||||||
void handleTicker(tscallback_t, void *, volatile bool *flag);
|
|
||||||
static void handleTickerFlag(volatile bool *flag);
|
|
||||||
|
|
||||||
public:
|
|
||||||
TickerScheduler(uint8_t size);
|
|
||||||
~TickerScheduler();
|
|
||||||
|
|
||||||
bool add(uint8_t i, uint32_t period, tscallback_t, void *, boolean shouldFireNow = false);
|
|
||||||
bool remove(uint8_t i);
|
|
||||||
bool enable(uint8_t i);
|
|
||||||
bool disable(uint8_t i);
|
|
||||||
void enableAll();
|
|
||||||
void disableAll();
|
|
||||||
void update();
|
|
||||||
};
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
/****************************************
|
|
||||||
* Include Libraries
|
|
||||||
****************************************/
|
|
||||||
#include "TheThingsMQTT.h"
|
|
||||||
#include "TickerScheduler.h"
|
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <PubSubClient.h>
|
|
||||||
|
|
||||||
#include <DNSServer.h>
|
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <WiFiManager.h>
|
|
||||||
#include <Adafruit_Sensor.h>
|
|
||||||
#include <DHT.h>
|
|
||||||
#include <DHT_U.h>
|
|
||||||
|
|
||||||
/****************************************
|
|
||||||
* Define Constants
|
|
||||||
****************************************/
|
|
||||||
#define TOKEN "" // Your TheThings TOKEN
|
|
||||||
#define WIFINAME "" //Your SSID
|
|
||||||
#define WIFIPASS "" // Your Wifi Pass
|
|
||||||
|
|
||||||
TheThings client(TOKEN);
|
|
||||||
|
|
||||||
#define DHTPIN 14 // Pin which is cosnnected to the DHT sensor.
|
|
||||||
// Uncomment the type of sensor in use:
|
|
||||||
//#define DHTTYPE DHT11 // DHT 11
|
|
||||||
#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
|
||||||
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
|
|
||||||
|
|
||||||
DHT_Unified dht(DHTPIN, DHTTYPE);
|
|
||||||
|
|
||||||
uint32_t delayMS;
|
|
||||||
#define TRIGGER_PIN 0
|
|
||||||
#define FRECUENCY 2000
|
|
||||||
char *AP="TEST_BQ";
|
|
||||||
String prefix="rel";
|
|
||||||
const char WiFiAPPSK[] = "prueba";
|
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
|
||||||
|
|
||||||
#define RELAY1 12
|
|
||||||
#define RELAY2 13
|
|
||||||
|
|
||||||
#define MEASUREMENT_TIME 30000 // Time in milisecons
|
|
||||||
|
|
||||||
float Temperature,Humidity;
|
|
||||||
TickerScheduler ts(1);
|
|
||||||
|
|
||||||
/****************************************
|
|
||||||
* Auxiliar Functions
|
|
||||||
****************************************/
|
|
||||||
|
|
||||||
//void configWiFi(){
|
|
||||||
// wifiManager.resetSettings();
|
|
||||||
// if(!wifiManager.autoConnect(AP,WiFiAPPSK)) {
|
|
||||||
// Serial.println("Reconfiguration called");
|
|
||||||
// delay(3000);
|
|
||||||
// //reset and try again, or maybe put it to deep sleep
|
|
||||||
// ESP.reset();
|
|
||||||
// delay(15000);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length) {
|
|
||||||
Serial.print("Message arrived");
|
|
||||||
// handle message arrived
|
|
||||||
String text = "";
|
|
||||||
for (int i = 0; i < length; i++)
|
|
||||||
text.concat((char)payload[i]);
|
|
||||||
Serial.println(text);
|
|
||||||
text.replace(" ", "");
|
|
||||||
text.toUpperCase();
|
|
||||||
if (text.indexOf("\"KEY\":\"REL1\"") >= 0) {
|
|
||||||
if (text.indexOf("\"VALUE\":\"ON\"") >= 0) digitalWrite(RELAY1,HIGH);
|
|
||||||
else if (text.indexOf("\"VALUE\":\"OFF\"") >= 0) digitalWrite(RELAY1,LOW);
|
|
||||||
}
|
|
||||||
else if (text.indexOf("\"KEY\":\"REL2\"") >= 0) {
|
|
||||||
if (text.indexOf("\"VALUE\":\"ON\"") >= 0) digitalWrite(RELAY2,HIGH);
|
|
||||||
else if (text.indexOf("\"VALUE\":\"OFF\"") >= 0) digitalWrite(RELAY2,LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float temperatureMeasurement(sensors_event_t event, DHT_Unified dht){
|
|
||||||
// Get temperature event and print its value.
|
|
||||||
dht.temperature().getEvent(&event);
|
|
||||||
if (isnan(event.temperature)) {
|
|
||||||
Serial.println("Error reading temperature!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.print("Temperature: ");
|
|
||||||
Serial.print(event.temperature);
|
|
||||||
Serial.println(" *C");
|
|
||||||
return event.temperature;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float humidityMeasurement(sensors_event_t event, DHT_Unified dht){
|
|
||||||
// Get humidity event and print its value.
|
|
||||||
dht.humidity().getEvent(&event);
|
|
||||||
if (isnan(event.relative_humidity)) {
|
|
||||||
Serial.println("Error reading humidity!");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.print("Humidity: ");
|
|
||||||
Serial.print(event.relative_humidity);
|
|
||||||
Serial.println("%");
|
|
||||||
return event.relative_humidity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void measureAndSend(){
|
|
||||||
sensors_event_t event;
|
|
||||||
Temperature=temperatureMeasurement(event,dht);
|
|
||||||
Humidity=humidityMeasurement(event,dht);
|
|
||||||
client.add("Temperature", Temperature);
|
|
||||||
client.add("Humidity", Humidity);
|
|
||||||
client.publish();
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************
|
|
||||||
* Main Functions
|
|
||||||
****************************************/
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
// put your setup code here, to run once:
|
|
||||||
Serial.begin(115200);
|
|
||||||
delay(100);
|
|
||||||
pinMode(RELAY1,OUTPUT);
|
|
||||||
pinMode(RELAY2,OUTPUT);
|
|
||||||
|
|
||||||
dht.begin();
|
|
||||||
sensor_t sensor;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// pinMode(TRIGGER_PIN, INPUT);
|
|
||||||
// attachInterrupt(digitalPinToInterrupt(TRIGGER_PIN), configWiFi, RISING);
|
|
||||||
//
|
|
||||||
// //sets timeout until configuration portal gets turned off
|
|
||||||
// //useful to make it all retry or go to sleep
|
|
||||||
// //in seconds
|
|
||||||
// wifiManager.setTimeout(280);
|
|
||||||
//
|
|
||||||
// //fetches ssid and pass and tries to connect
|
|
||||||
// //if it does not connect it starts an access point with the specified name
|
|
||||||
// //here "AutoConnectAP"
|
|
||||||
// //and goes into a blocking loop awaiting configuration
|
|
||||||
// if(!wifiManager.autoConnect(AP,WiFiAPPSK)) {
|
|
||||||
// Serial.println("failed to connect and hit timeout");
|
|
||||||
// delay(3000);
|
|
||||||
// //reset and try again, or maybe put it to deep sleep
|
|
||||||
// //ESP.reset();
|
|
||||||
// delay(FRECUENCY);
|
|
||||||
// }
|
|
||||||
// //if you get here you have connected to the WiFi
|
|
||||||
// Serial.println("connected...yeey :)");
|
|
||||||
|
|
||||||
client.wifiConnection(WIFINAME, WIFIPASS);
|
|
||||||
|
|
||||||
//client.wifiConnection2();
|
|
||||||
client.begin(callback);
|
|
||||||
client.subscribe(); //Insert the dataSource and Variable's Labels
|
|
||||||
|
|
||||||
ts.add(0, MEASUREMENT_TIME, [&](void*) { measureAndSend(); }, nullptr, false);
|
|
||||||
ts.enableAll();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
ts.update();
|
|
||||||
|
|
||||||
if(!client.connected()){
|
|
||||||
client.reconnect();
|
|
||||||
client.subscribe(); //Insert the dataSource and Variable's Labels
|
|
||||||
}
|
|
||||||
client.loop();
|
|
||||||
|
|
||||||
}
|
|
||||||
81
lib/TickerScheduler/README.md
Normal file
81
lib/TickerScheduler/README.md
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
# TickerScheduler
|
||||||
|
Simple scheduler for ESP8266 Arduino based on Ticker
|
||||||
|
|
||||||
|
### Initialization
|
||||||
|
|
||||||
|
`TickerScheduler(uint size);`
|
||||||
|
|
||||||
|
| Param | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| size | Amount of task Tickers to initialize |
|
||||||
|
|
||||||
|
**Example**:
|
||||||
|
|
||||||
|
`TickerScheduler ts(5)`
|
||||||
|
|
||||||
|
|
||||||
|
### Add task
|
||||||
|
|
||||||
|
`boolean add(uint i, uint32_t period, tscallback_t f, boolean shouldFireNow = false); `
|
||||||
|
|
||||||
|
| Param | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| i | Task ID |
|
||||||
|
| period | Task execution period in ms |
|
||||||
|
| f | Task callback |
|
||||||
|
| shouldFireNow| `true` if you want to execute task right after first scheduler update or wait next scheduled start |
|
||||||
|
|
||||||
|
**Returns**:
|
||||||
|
|
||||||
|
`true` - task added sucessfully
|
||||||
|
|
||||||
|
`false` - task was not added
|
||||||
|
|
||||||
|
**Example**:
|
||||||
|
|
||||||
|
`ts.add(0, 3000, sendData)`
|
||||||
|
|
||||||
|
### Execute scheduler in `loop()`
|
||||||
|
|
||||||
|
`ts.update()`
|
||||||
|
|
||||||
|
### Remove task
|
||||||
|
|
||||||
|
`boolean remove(uint i)`
|
||||||
|
|
||||||
|
**Returns**:
|
||||||
|
|
||||||
|
`true` - task removed sucessfully
|
||||||
|
|
||||||
|
`false` - task was not removed
|
||||||
|
|
||||||
|
| Param | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| i | Task ID |
|
||||||
|
|
||||||
|
### Enable/Disable task
|
||||||
|
|
||||||
|
`boolean enable(uint i)`
|
||||||
|
|
||||||
|
`boolean disable(uint i)`
|
||||||
|
|
||||||
|
**Returns**:
|
||||||
|
|
||||||
|
`true` - task enabled/disabled sucessfully
|
||||||
|
|
||||||
|
`false` - task was not enabled/disabled
|
||||||
|
|
||||||
|
| Param | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| i | Task ID |
|
||||||
|
|
||||||
|
### Enable / disable all tasks
|
||||||
|
|
||||||
|
`void enableAll()`
|
||||||
|
|
||||||
|
`void disableAll()`
|
||||||
|
|
||||||
|
### TODO
|
||||||
|
|
||||||
|
* Task callback parameters support
|
||||||
|
* ...
|
||||||
@@ -19,13 +19,13 @@ TickerScheduler::~TickerScheduler()
|
|||||||
this->size = 0;
|
this->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TickerScheduler::handleTickerFlag(volatile bool * flag)
|
void TickerScheduler::handleTickerFlag(bool * flag)
|
||||||
{
|
{
|
||||||
if (!*flag)
|
if (!*flag)
|
||||||
*flag = true;
|
*flag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TickerScheduler::handleTicker(tscallback_t f, void * arg, volatile bool * flag)
|
void TickerScheduler::handleTicker(tscallback_t f, void * arg, bool * flag)
|
||||||
{
|
{
|
||||||
if (*flag)
|
if (*flag)
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ bool TickerScheduler::enable(uint8_t i)
|
|||||||
if (i >= this->size || !this->items[i].is_used)
|
if (i >= this->size || !this->items[i].is_used)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
volatile bool * flag = &this->items[i].flag;
|
bool * flag = &this->items[i].flag;
|
||||||
this->items[i].t.attach_ms(this->items[i].period, TickerScheduler::handleTickerFlag, flag);
|
this->items[i].t.attach_ms(this->items[i].period, TickerScheduler::handleTickerFlag, flag);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
91
lib/TickerScheduler/TickerScheduler.h
Normal file
91
lib/TickerScheduler/TickerScheduler.h
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#ifndef TICKERSCHEDULER_H
|
||||||
|
#define TICKERSCHEDULER_H
|
||||||
|
|
||||||
|
#if defined(ARDUINO) && ARDUINO >= 100
|
||||||
|
#include "Arduino.h"
|
||||||
|
#endif
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ARDUINO_ARCH_AVR
|
||||||
|
class Ticker
|
||||||
|
{
|
||||||
|
typedef void(*ticker_callback_t)(bool*);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool is_attached = false;
|
||||||
|
uint32_t period = 0;
|
||||||
|
uint32_t last_tick = 0;
|
||||||
|
ticker_callback_t callback;
|
||||||
|
bool *callback_argument;
|
||||||
|
public:
|
||||||
|
void Tick()
|
||||||
|
{
|
||||||
|
if (is_attached && millis() - last_tick >= period)
|
||||||
|
{
|
||||||
|
callback(callback_argument);
|
||||||
|
last_tick = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void detach()
|
||||||
|
{
|
||||||
|
this->is_attached = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename TArg> void attach_ms(uint32_t milliseconds, void(*callback)(TArg), TArg arg)
|
||||||
|
{
|
||||||
|
this->period = milliseconds;
|
||||||
|
this->callback = callback;
|
||||||
|
this->callback_argument = arg;
|
||||||
|
this->is_attached = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
#include <Ticker.h>
|
||||||
|
#include <functional>
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
void tickerFlagHandle(volatile bool * flag);
|
||||||
|
|
||||||
|
#ifdef _GLIBCXX_FUNCTIONAL
|
||||||
|
typedef std::function<void(void*)> tscallback_t;
|
||||||
|
#else
|
||||||
|
typedef void(*tscallback_t)(void*);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct TickerSchedulerItem
|
||||||
|
{
|
||||||
|
Ticker t;
|
||||||
|
bool flag = false;
|
||||||
|
tscallback_t cb;
|
||||||
|
void * cb_arg;
|
||||||
|
uint32_t period;
|
||||||
|
volatile bool is_used = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TickerScheduler
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
uint8_t size;
|
||||||
|
TickerSchedulerItem *items = NULL;
|
||||||
|
|
||||||
|
void handleTicker(tscallback_t, void *, bool * flag);
|
||||||
|
static void handleTickerFlag(bool * flag);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TickerScheduler(uint8_t size);
|
||||||
|
~TickerScheduler();
|
||||||
|
|
||||||
|
bool add(uint8_t i, uint32_t period, tscallback_t, void *, boolean shouldFireNow = false);
|
||||||
|
bool remove(uint8_t i);
|
||||||
|
bool enable(uint8_t i);
|
||||||
|
bool disable(uint8_t i);
|
||||||
|
void enableAll();
|
||||||
|
void disableAll();
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
29
lib/TickerScheduler/example/blink/blink/blink.ino
Normal file
29
lib/TickerScheduler/example/blink/blink/blink.ino
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include <TickerScheduler.h>
|
||||||
|
|
||||||
|
#define LED1 4
|
||||||
|
#define LED2 5
|
||||||
|
|
||||||
|
TickerScheduler ts(2);
|
||||||
|
|
||||||
|
void blink1() {
|
||||||
|
digitalWrite(LED1, !digitalRead(LED1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void blink2() {
|
||||||
|
digitalWrite(LED2, !digitalRead(LED2));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(LED1, OUTPUT);
|
||||||
|
digitalWrite(LED1, LOW);
|
||||||
|
|
||||||
|
pinMode(LED2, OUTPUT);
|
||||||
|
digitalWrite(LED2, LOW);
|
||||||
|
|
||||||
|
ts.add(0, 1000, [&](void *) { blink1(); }, nullptr, true);
|
||||||
|
ts.add(1, 3000, [&](void *) { blink2(); }, nullptr, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
ts.update();
|
||||||
|
}
|
||||||
@@ -17,9 +17,8 @@ lib_deps=
|
|||||||
ESP32Servo
|
ESP32Servo
|
||||||
Bounce2
|
Bounce2
|
||||||
PubSubClient
|
PubSubClient
|
||||||
iothubclientlonghaultests_bld
|
|
||||||
ESP8266-StringCommand
|
ESP8266-StringCommand
|
||||||
|
|
||||||
[env:esp32dev]
|
[env:esp32dev]
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
|
|||||||
11
src/Cmd.cpp
11
src/Cmd.cpp
@@ -1,11 +1,6 @@
|
|||||||
#include "Cmd.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "Scenario.h"
|
|
||||||
#include "TimeUtils.h"
|
|
||||||
#include "Widgets.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "push_pushingbox.h"
|
#include "push_pushingbox.h"
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void CMD_init() {
|
void CMD_init() {
|
||||||
sCmd.addCommand("button", button);
|
sCmd.addCommand("button", button);
|
||||||
@@ -74,8 +69,8 @@ void CMD_init() {
|
|||||||
sCmd.addCommand("inputTime", inputTime);
|
sCmd.addCommand("inputTime", inputTime);
|
||||||
sCmd.addCommand("timeSet", timeSet);
|
sCmd.addCommand("timeSet", timeSet);
|
||||||
|
|
||||||
sCmd.addCommand("timerStart", timerStart);
|
sCmd.addCommand("timerStart", timerStart_);
|
||||||
sCmd.addCommand("timerStop", timerStop);
|
sCmd.addCommand("timerStop", timerStop_);
|
||||||
|
|
||||||
sCmd.addCommand("text", text);
|
sCmd.addCommand("text", text);
|
||||||
sCmd.addCommand("textSet", textSet);
|
sCmd.addCommand("textSet", textSet);
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
|
#include "Global.h"
|
||||||
#include <FS.h>
|
|
||||||
#include <SPIFFS.h>
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void File_system_init() {
|
void File_system_init() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|||||||
11
src/Init.cpp
11
src/Init.cpp
@@ -1,11 +1,4 @@
|
|||||||
#include "Init.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "Logging.h"
|
|
||||||
#include "Scenario.h"
|
|
||||||
#include "Timers.h"
|
|
||||||
#include "Widgets.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void All_init() {
|
void All_init() {
|
||||||
server.on("/init", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/init", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
@@ -73,7 +66,7 @@ void Device_init() {
|
|||||||
|
|
||||||
int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
|
int array_sz = sizeof(sensors_reading_map) / sizeof(sensors_reading_map[0]);
|
||||||
|
|
||||||
for (int i = 0; i <= array_sz; i++) {
|
for (int i = 0; i < array_sz; i++) {
|
||||||
sensors_reading_map[i] = 0;
|
sensors_reading_map[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#include "Logging.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "Mqtt.h"
|
void sendLogData(String file, String topic);
|
||||||
#include "TimeUtils.h"
|
|
||||||
#include "Widgets.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
#ifdef logging_enable
|
#ifdef logging_enable
|
||||||
//===============================================Логирование============================================================
|
//===============================================Логирование============================================================
|
||||||
@@ -105,7 +101,8 @@ void choose_log_date_and_send() {
|
|||||||
String all_line = logging_value_names_list;
|
String all_line = logging_value_names_list;
|
||||||
while (all_line.length() != 0) {
|
while (all_line.length() != 0) {
|
||||||
String tmp = selectToMarker(all_line, ",");
|
String tmp = selectToMarker(all_line, ",");
|
||||||
sendLogData("log." + tmp + ".txt", tmp + "_ch");
|
sendLogData("log." + tmp + ".txt", tmp + "_ch"
|
||||||
|
);
|
||||||
all_line = deleteBeforeDelimiter(all_line, ",");
|
all_line = deleteBeforeDelimiter(all_line, ",");
|
||||||
}
|
}
|
||||||
all_line = "";
|
all_line = "";
|
||||||
|
|||||||
15
src/Mqtt.cpp
15
src/Mqtt.cpp
@@ -1,10 +1,11 @@
|
|||||||
#include "Mqtt.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
|
String stateMQTT();
|
||||||
#include "WiFi.h"
|
void sendAllData();
|
||||||
#include "main.h"
|
void sendAllWigets();
|
||||||
#include "set.h"
|
void sendSTATUS(String topik, String state);
|
||||||
|
void outcoming_date();
|
||||||
|
|
||||||
//===============================================ИНИЦИАЛИЗАЦИЯ================================================
|
//===============================================ИНИЦИАЛИЗАЦИЯ================================================
|
||||||
void MQTT_init() {
|
void MQTT_init() {
|
||||||
@@ -217,7 +218,7 @@ void sendAllWigets() {
|
|||||||
}
|
}
|
||||||
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
configFile.seek(0, SeekSet); //поставим курсор в начало файла
|
||||||
while (configFile.position() != configFile.size()) {
|
while (configFile.position() != configFile.size()) {
|
||||||
String widget_to_send = configFile.readStringUntil("\r\n");
|
String widget_to_send = configFile.readStringUntil('\n');
|
||||||
Serial.println("[V] " + widget_to_send);
|
Serial.println("[V] " + widget_to_send);
|
||||||
sendMQTT("config", widget_to_send);
|
sendMQTT("config", widget_to_send);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "Scenario.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void handleScenario() {
|
void handleScenario() {
|
||||||
if (jsonReadStr(configSetup, "scenario") == "1") {
|
if (jsonReadStr(configSetup, "scenario") == "1") {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "Sensors.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void sensors_init() {
|
void sensors_init() {
|
||||||
ts.add(
|
ts.add(
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "TimeUtils.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void Time_Init() {
|
void Time_Init() {
|
||||||
server.on("/time", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/time", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
#include "Timers.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "Scenario.h"
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void Timer_countdown_init() {
|
void Timer_countdown_init() {
|
||||||
ts.add(
|
ts.add(
|
||||||
@@ -33,7 +29,7 @@ void Timer_countdown_init() {
|
|||||||
nullptr, true);
|
nullptr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerStart() {
|
void timerStart_() {
|
||||||
String number = sCmd.next();
|
String number = sCmd.next();
|
||||||
String period_of_time = sCmd.next();
|
String period_of_time = sCmd.next();
|
||||||
String type = sCmd.next();
|
String type = sCmd.next();
|
||||||
@@ -64,7 +60,7 @@ void addTimer(String number, String time) {
|
|||||||
//Serial.println("ura");
|
//Serial.println("ura");
|
||||||
}
|
}
|
||||||
|
|
||||||
void timerStop() {
|
void timerStop_() {
|
||||||
String number = sCmd.next();
|
String number = sCmd.next();
|
||||||
delTimer(number);
|
delTimer(number);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "Upgrade.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
static const char* UPGRADE_URL PROGMEM = "http://91.204.228.124:1100/update/";
|
static const char* UPGRADE_URL PROGMEM = "http://91.204.228.124:1100/update/";
|
||||||
|
|
||||||
@@ -20,11 +17,11 @@ void initUpgrade() {
|
|||||||
String last_version = WiFi.status() == WL_CONNECTED ? getURL(getUpgradeUrl()) : "";
|
String last_version = WiFi.status() == WL_CONNECTED ? getURL(getUpgradeUrl()) : "";
|
||||||
jsonWriteStr(configSetup, "last_version", last_version);
|
jsonWriteStr(configSetup, "last_version", last_version);
|
||||||
|
|
||||||
Serial.printf("[i] Last firmware version: %s\n", last_version);
|
Serial.printf("[i] Last firmware version: %s\n", last_version.c_str());
|
||||||
|
|
||||||
server.on("/check", HTTP_GET, [last_version](AsyncWebServerRequest* request) {
|
server.on("/check", HTTP_GET, [last_version](AsyncWebServerRequest* request) {
|
||||||
upgrade_url = true;
|
upgrade_url = true;
|
||||||
Serial.printf("[i] Last firmware version: %s\n", last_version);
|
Serial.printf("[i] Last firmware version: %s\n", last_version.c_str());
|
||||||
String tmp = "{}";
|
String tmp = "{}";
|
||||||
if (WiFi.status() == WL_CONNECTED) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
if (mb_4_of_memory) {
|
if (mb_4_of_memory) {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "main.h"
|
#include "Global.h"
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void Web_server_init() {
|
void Web_server_init() {
|
||||||
#ifdef OTA_enable
|
#ifdef OTA_enable
|
||||||
|
|||||||
@@ -1,53 +1,64 @@
|
|||||||
#include "main.h"
|
#include "Global.h"
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void WIFI_init() {
|
boolean RouterFind(String ssid);
|
||||||
|
|
||||||
|
void WIFI_init()
|
||||||
|
{
|
||||||
// --------------------Получаем ssid password со страницы
|
// --------------------Получаем ssid password со страницы
|
||||||
server.on("/ssid", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/ssid", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
if (request->hasArg("ssid")) {
|
if (request->hasArg("ssid"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "ssid", request->getParam("ssid")->value());
|
jsonWriteStr(configSetup, "ssid", request->getParam("ssid")->value());
|
||||||
}
|
}
|
||||||
if (request->hasArg("password")) {
|
if (request->hasArg("password"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "password", request->getParam("password")->value());
|
jsonWriteStr(configSetup, "password", request->getParam("password")->value());
|
||||||
}
|
}
|
||||||
saveConfig(); // Функция сохранения данных во Flash
|
saveConfig(); // Функция сохранения данных во Flash
|
||||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||||
});
|
});
|
||||||
// --------------------Получаем ssidAP passwordAP со страницы
|
// --------------------Получаем ssidAP passwordAP со страницы
|
||||||
server.on("/ssidap", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/ssidap", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
if (request->hasArg("ssidAP")) {
|
if (request->hasArg("ssidAP"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "ssidAP", request->getParam("ssidAP")->value());
|
jsonWriteStr(configSetup, "ssidAP", request->getParam("ssidAP")->value());
|
||||||
}
|
}
|
||||||
if (request->hasArg("passwordAP")) {
|
if (request->hasArg("passwordAP"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "passwordAP", request->getParam("passwordAP")->value());
|
jsonWriteStr(configSetup, "passwordAP", request->getParam("passwordAP")->value());
|
||||||
}
|
}
|
||||||
saveConfig(); // Функция сохранения данных во Flash
|
saveConfig(); // Функция сохранения данных во Flash
|
||||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||||
});
|
});
|
||||||
|
|
||||||
// --------------------Получаем логин и пароль для web со страницы
|
// --------------------Получаем логин и пароль для web со страницы
|
||||||
server.on("/web", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/web", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
if (request->hasArg("web_login")) {
|
if (request->hasArg("web_login"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "web_login", request->getParam("web_login")->value());
|
jsonWriteStr(configSetup, "web_login", request->getParam("web_login")->value());
|
||||||
}
|
}
|
||||||
if (request->hasArg("web_pass")) {
|
if (request->hasArg("web_pass"))
|
||||||
|
{
|
||||||
jsonWriteStr(configSetup, "web_pass", request->getParam("web_pass")->value());
|
jsonWriteStr(configSetup, "web_pass", request->getParam("web_pass")->value());
|
||||||
}
|
}
|
||||||
saveConfig(); // Функция сохранения данных во Flash
|
saveConfig(); // Функция сохранения данных во Flash
|
||||||
//Web_server_init();
|
//Web_server_init();
|
||||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on("/restart", HTTP_GET, [](AsyncWebServerRequest* request) {
|
server.on("/restart", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||||
if (request->hasArg("device")) {
|
if (request->hasArg("device"))
|
||||||
if (request->getParam("device")->value() == "ok") ESP.restart();
|
{
|
||||||
|
if (request->getParam("device")->value() == "ok")
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
request->send(200, "text/text", "OK"); // отправляем ответ о выполнении
|
||||||
});
|
});
|
||||||
ROUTER_Connecting();
|
ROUTER_Connecting();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ROUTER_Connecting() {
|
void ROUTER_Connecting()
|
||||||
|
{
|
||||||
led_blink("slow");
|
led_blink("slow");
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
@@ -57,17 +68,22 @@ void ROUTER_Connecting() {
|
|||||||
String _password = jsonReadStr(configSetup, "password");
|
String _password = jsonReadStr(configSetup, "password");
|
||||||
//WiFi.persistent(false);
|
//WiFi.persistent(false);
|
||||||
|
|
||||||
if (_ssid == "" && _password == "") {
|
if (_ssid == "" && _password == "")
|
||||||
|
{
|
||||||
WiFi.begin();
|
WiFi.begin();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
WiFi.begin(_ssid.c_str(), _password.c_str());
|
WiFi.begin(_ssid.c_str(), _password.c_str());
|
||||||
Serial.print("ssid: ");
|
Serial.print("ssid: ");
|
||||||
Serial.println(_ssid);
|
Serial.println(_ssid);
|
||||||
}
|
}
|
||||||
// Делаем проверку подключения до тех пор пока счетчик tries
|
// Делаем проверку подключения до тех пор пока счетчик tries
|
||||||
// не станет равен нулю или не получим подключение
|
// не станет равен нулю или не получим подключение
|
||||||
while (--tries && WiFi.status() != WL_CONNECTED) {
|
while (--tries && WiFi.status() != WL_CONNECTED)
|
||||||
if (WiFi.status() == WL_CONNECT_FAILED) {
|
{
|
||||||
|
if (WiFi.status() == WL_CONNECT_FAILED)
|
||||||
|
{
|
||||||
Serial.println("[E] password is not correct");
|
Serial.println("[E] password is not correct");
|
||||||
tries = 1;
|
tries = 1;
|
||||||
jsonWriteInt(optionJson, "pass_status", 1);
|
jsonWriteInt(optionJson, "pass_status", 1);
|
||||||
@@ -77,9 +93,12 @@ void ROUTER_Connecting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
StartAPMode();
|
StartAPMode();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.println("[V] WiFi connected");
|
Serial.println("[V] WiFi connected");
|
||||||
Serial.print("[V] IP address: http://");
|
Serial.print("[V] IP address: http://");
|
||||||
Serial.print(WiFi.localIP());
|
Serial.print(WiFi.localIP());
|
||||||
@@ -90,7 +109,8 @@ void ROUTER_Connecting() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartAPMode() {
|
bool StartAPMode()
|
||||||
|
{
|
||||||
Serial.println("WiFi up AP");
|
Serial.println("WiFi up AP");
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
|
|
||||||
@@ -105,11 +125,13 @@ bool StartAPMode() {
|
|||||||
Serial.println(myIP);
|
Serial.println(myIP);
|
||||||
jsonWriteStr(configJson, "ip", myIP.toString());
|
jsonWriteStr(configJson, "ip", myIP.toString());
|
||||||
|
|
||||||
if (jsonReadInt(optionJson, "pass_status") != 1) {
|
if (jsonReadInt(optionJson, "pass_status") != 1)
|
||||||
|
{
|
||||||
ts.add(
|
ts.add(
|
||||||
ROUTER_SEARCHING, 10 * 1000, [&](void*) {
|
ROUTER_SEARCHING, 10 * 1000, [&](void *) {
|
||||||
Serial.println("->try find router");
|
Serial.println("->try find router");
|
||||||
if (RouterFind(jsonReadStr(configSetup, "ssid"))) {
|
if (RouterFind(jsonReadStr(configSetup, "ssid")))
|
||||||
|
{
|
||||||
ts.remove(ROUTER_SEARCHING);
|
ts.remove(ROUTER_SEARCHING);
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
ROUTER_Connecting();
|
ROUTER_Connecting();
|
||||||
@@ -121,43 +143,52 @@ bool StartAPMode() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean RouterFind(String ssid) {
|
boolean RouterFind(String ssid)
|
||||||
|
{
|
||||||
|
bool res = false;
|
||||||
|
|
||||||
int n = WiFi.scanComplete();
|
int n = WiFi.scanComplete();
|
||||||
Serial.println("n = " + String(n));
|
Serial.println("n = " + String(n));
|
||||||
if (n == -2) { //Сканирование не было запущено, запускаем
|
if (n == -2)
|
||||||
|
{ //Сканирование не было запущено, запускаем
|
||||||
Serial.println("[WIFI][i] scanning has not been triggered, starting scanning");
|
Serial.println("[WIFI][i] scanning has not been triggered, starting scanning");
|
||||||
WiFi.scanNetworks(true, false); //async, show_hidden
|
WiFi.scanNetworks(true, false); //async, show_hidde
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (n == -1) { //Сканирование все еще выполняется
|
else if (n == -1)
|
||||||
|
{ //Сканирование все еще выполняется
|
||||||
Serial.println("[WIFI][i] scanning still in progress");
|
Serial.println("[WIFI][i] scanning still in progress");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (n == 0) { //ни одна сеть не найдена
|
else if (n == 0)
|
||||||
|
{ //ни одна сеть не найдена
|
||||||
Serial.println("[WIFI][i] no any wifi sations, starting scanning");
|
Serial.println("[WIFI][i] no any wifi sations, starting scanning");
|
||||||
WiFi.scanNetworks(true, false);
|
WiFi.scanNetworks(true, false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (n > 0) {
|
else if (n > 0)
|
||||||
for (int i = 0; i <= n; i++) {
|
{
|
||||||
if (WiFi.SSID(i) == ssid) {
|
for (int i = 0; i <= n; i++)
|
||||||
|
{
|
||||||
|
if (WiFi.SSID(i) == ssid)
|
||||||
|
{
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
return true;
|
res = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(")");
|
Serial.print(")");
|
||||||
//Serial.print(ssid);
|
if (i == n)
|
||||||
//Serial.print("<=>");
|
{
|
||||||
if (i == n) {
|
|
||||||
Serial.print(WiFi.SSID(i));
|
Serial.print(WiFi.SSID(i));
|
||||||
Serial.println("; ");
|
Serial.println("; ");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Serial.print(WiFi.SSID(i));
|
Serial.print(WiFi.SSID(i));
|
||||||
Serial.println("; ");
|
Serial.println("; ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WiFi.scanDelete();
|
WiFi.scanDelete();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "Widgets.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void createWidget(String widget_name, String page_name, String page_number, String file, String topic) {
|
void createWidget(String widget_name, String page_name, String page_number, String file, String topic) {
|
||||||
String widget;
|
String widget;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "i2c_bus.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void do_i2c_scanning() {
|
void do_i2c_scanning() {
|
||||||
if (i2c_scanning) {
|
if (i2c_scanning) {
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
#include "Cmd.h"
|
#include "Global.h"
|
||||||
#include "FileSystem.h"
|
|
||||||
#include "Sensors.h"
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
File_system_init();
|
File_system_init();
|
||||||
|
|||||||
39
src/main.cpp
39
src/main.cpp
@@ -1,6 +1,4 @@
|
|||||||
#include "main.h"
|
#include "Global.h"
|
||||||
|
|
||||||
#include "set.h"
|
|
||||||
|
|
||||||
String jsonReadStr(String& json, String name) {
|
String jsonReadStr(String& json, String name) {
|
||||||
DynamicJsonBuffer jsonBuffer;
|
DynamicJsonBuffer jsonBuffer;
|
||||||
@@ -61,6 +59,9 @@ void saveConfig() {
|
|||||||
writeFile("config.json", configSetup);
|
writeFile("config.json", configSetup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================================================
|
||||||
|
//=============================================STRING===================================================
|
||||||
|
|
||||||
// --------Выделяем строку от конца строки до маркера-----------------------------------------------------------
|
// --------Выделяем строку от конца строки до маркера-----------------------------------------------------------
|
||||||
String selectToMarkerLast(String str, String found) {
|
String selectToMarkerLast(String str, String found) {
|
||||||
int p = str.lastIndexOf(found);
|
int p = str.lastIndexOf(found);
|
||||||
@@ -121,25 +122,24 @@ int count(String str, String found) {
|
|||||||
return i; // Достигли пустой строки и ничего не нашли
|
return i; // Достигли пустой строки и ничего не нашли
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean isDigitStr(String str) {
|
boolean isDigitStr(String str) {
|
||||||
if (str.length() == 1) {
|
for (int i = 0; i < str.length(); i++) {
|
||||||
return Digit(str);
|
if (!isDigit(str.charAt(i))) {
|
||||||
}
|
return false;
|
||||||
if (str.length() > 1) {
|
|
||||||
for (int i = 0; i < str.length(); i++) {
|
|
||||||
if (!Digit(String(str.charAt(i)))) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean Digit(String str) {
|
|
||||||
if (str == "0" || str == "1" || str == "2" || str == "3" || str == "4" || str == "5" || str == "6" || str == "7" || str == "8" || str == "9") {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return str.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// boolean digit(String str) {
|
||||||
|
// if (str == "0" || str == "1" || str == "2" || str == "3" || str == "4" || str == "5" || str == "6" || str == "7" || str == "8" || str == "9") {
|
||||||
|
// return true;
|
||||||
|
// } else {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
String getURL(String urls) {
|
String getURL(String urls) {
|
||||||
String answer = "";
|
String answer = "";
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
@@ -153,10 +153,10 @@ String getURL(String urls) {
|
|||||||
http.end();
|
http.end();
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
//===================================================================================================================
|
//===================================================================================================================
|
||||||
//===========================================FILES===================================================================
|
//===========================================FILES===================================================================
|
||||||
// ------------- Добавление файла -----------------------------------------------------------------------------------
|
// ------------- Добавление файла -----------------------------------------------------------------------------------
|
||||||
String safeDataToFile(String data, String Folder) {
|
void safeDataToFile(String data, String Folder) {
|
||||||
//String fileName = GetDate();
|
//String fileName = GetDate();
|
||||||
String fileName;
|
String fileName;
|
||||||
fileName.toLowerCase();
|
fileName.toLowerCase();
|
||||||
@@ -168,6 +168,7 @@ String safeDataToFile(String data, String Folder) {
|
|||||||
Serial.println(fileName);
|
Serial.println(fileName);
|
||||||
jsonWriteStr(configJson, "test", fileName);
|
jsonWriteStr(configJson, "test", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------- Чтение файла в строку -------------------------------------------------------------------------------
|
// ------------- Чтение файла в строку -------------------------------------------------------------------------------
|
||||||
String readFile(String fileName, size_t len) {
|
String readFile(String fileName, size_t len) {
|
||||||
File configFile = SPIFFS.open("/" + fileName, "r");
|
File configFile = SPIFFS.open("/" + fileName, "r");
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
void handleUdp_esp32();
|
||||||
|
void add_dev_in_list(String fileName, String id, String dev_name, String ip);
|
||||||
|
|
||||||
#ifdef UDP_enable
|
#ifdef UDP_enable
|
||||||
void UDP_init() {
|
void UDP_init() {
|
||||||
server.on("/udp", HTTP_GET, [](AsyncWebServerRequest * request) {
|
server.on("/udp", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||||
|
|||||||
Reference in New Issue
Block a user