mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
cleaning
This commit is contained in:
@@ -1,56 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
class BusScanner {
|
|
||||||
public:
|
|
||||||
BusScanner(const char* tag, String& out, size_t tries) : _found{0},
|
|
||||||
_tries{tries},
|
|
||||||
_out{&out} {
|
|
||||||
_tag = new char(strlen(tag) + 1);
|
|
||||||
strcpy(_tag, tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scan() {
|
|
||||||
init();
|
|
||||||
bool res;
|
|
||||||
do {
|
|
||||||
res = syncScan();
|
|
||||||
} while (!res && --_tries);
|
|
||||||
|
|
||||||
if (!_found) {
|
|
||||||
addResult("не найдено");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* tag() {
|
|
||||||
return _tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void init(){};
|
|
||||||
|
|
||||||
virtual boolean syncScan() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void addResult(const String& str) {
|
|
||||||
_out->concat(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
void addResult(uint8_t addr, boolean last = true) {
|
|
||||||
_found++;
|
|
||||||
String str = "0x";
|
|
||||||
if (addr < 16) {
|
|
||||||
str += "0";
|
|
||||||
}
|
|
||||||
str += String(addr, HEX);
|
|
||||||
str += !last ? ", " : ", ";
|
|
||||||
addResult(str);
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
char* _tag;
|
|
||||||
size_t _found;
|
|
||||||
size_t _tries;
|
|
||||||
String* _out;
|
|
||||||
};
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Bus/BusScanner.h"
|
|
||||||
#include "Bus/I2CScanner.h"
|
|
||||||
#include "Consts.h"
|
|
||||||
#include "Utils/JsonUtils.h"
|
|
||||||
|
|
||||||
class BusScannerFactory {
|
|
||||||
public:
|
|
||||||
static BusScanner* get(String& config, BusScanner_t type, String& str) {
|
|
||||||
switch (type) {
|
|
||||||
case BS_I2C:
|
|
||||||
return new I2CScanner(str);
|
|
||||||
default:
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Bus/BusScanner.h"
|
|
||||||
|
|
||||||
class I2CScanner : public BusScanner {
|
|
||||||
public:
|
|
||||||
I2CScanner(String& out);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void init() override;
|
|
||||||
virtual boolean syncScan() override;
|
|
||||||
};
|
|
||||||
@@ -1,31 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
/*
|
|
||||||
* Main consts
|
//=================Firmeare=================
|
||||||
*/
|
|
||||||
#define FIRMWARE_NAME "esp8266-iotm"
|
#define FIRMWARE_NAME "esp8266-iotm"
|
||||||
#define FIRMWARE_VERSION 240
|
#define FIRMWARE_VERSION 240
|
||||||
|
|
||||||
#define NUM_BUTTONS 6
|
|
||||||
#define LED_PIN 2
|
|
||||||
#define FLASH_4MB true
|
#define FLASH_4MB true
|
||||||
|
|
||||||
|
//=================System===================
|
||||||
|
#define NUM_BUTTONS 6
|
||||||
|
#define LED_PIN 2
|
||||||
|
|
||||||
|
//=================MQTT=====================
|
||||||
#define MQTT_RECONNECT_INTERVAL 20000
|
#define MQTT_RECONNECT_INTERVAL 20000
|
||||||
|
|
||||||
|
//===============Telemetry==================
|
||||||
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
|
#define TELEMETRY_UPDATE_INTERVAL_MIN 60
|
||||||
|
|
||||||
|
//=============Configuration================
|
||||||
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
#define DEVICE_CONFIG_FILE "s.conf.csv"
|
||||||
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
#define DEVICE_SCENARIO_FILE "s.scen.txt"
|
||||||
|
|
||||||
#define DEFAULT_PRESET 100
|
//=============System parts=================
|
||||||
#define DEFAULT_SCENARIO 100
|
|
||||||
|
|
||||||
#define TAG_ONE_WIRE "oneWire"
|
|
||||||
#define TAG_I2C "i2c"
|
|
||||||
#define TAG_ONE_WIRE_PIN "oneWirePin"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Optional
|
|
||||||
*/
|
|
||||||
//#define OTA_UPDATES_ENABLED
|
//#define OTA_UPDATES_ENABLED
|
||||||
//#define MDNS_ENABLED
|
//#define MDNS_ENABLED
|
||||||
//#define WEBSOCKET_ENABLED
|
//#define WEBSOCKET_ENABLED
|
||||||
@@ -33,34 +27,25 @@
|
|||||||
//#define UDP_ENABLED
|
//#define UDP_ENABLED
|
||||||
#define SSDP_EN
|
#define SSDP_EN
|
||||||
|
|
||||||
/*
|
//=========Sensors enable/disable===========
|
||||||
* Sensor
|
|
||||||
*/
|
|
||||||
#define TANK_LEVEL_SAMPLES 10
|
#define TANK_LEVEL_SAMPLES 10
|
||||||
#define LEVEL_ENABLED
|
#define LEVEL_ENABLED
|
||||||
|
|
||||||
#define ANALOG_ENABLED
|
#define ANALOG_ENABLED
|
||||||
|
|
||||||
#define DALLAS_ENABLED
|
#define DALLAS_ENABLED
|
||||||
#define DHT_ENABLED
|
#define DHT_ENABLED
|
||||||
|
|
||||||
#define BMP_ENABLED
|
#define BMP_ENABLED
|
||||||
|
|
||||||
#define BME_ENABLED
|
#define BME_ENABLED
|
||||||
|
|
||||||
/*
|
//=========Gears enable/disable===========
|
||||||
* Gears
|
|
||||||
*/
|
|
||||||
#define STEPPER_ENABLED
|
#define STEPPER_ENABLED
|
||||||
#define SERVO_ENABLED
|
#define SERVO_ENABLED
|
||||||
|
|
||||||
/*
|
//=========Other enable/disable===========
|
||||||
* Other
|
|
||||||
*/
|
|
||||||
#define LOGGING_ENABLED
|
#define LOGGING_ENABLED
|
||||||
#define SERIAL_ENABLED
|
#define SERIAL_ENABLED
|
||||||
#define PUSH_ENABLED
|
#define PUSH_ENABLED
|
||||||
|
|
||||||
|
|
||||||
struct Time_t {
|
struct Time_t {
|
||||||
uint8_t second;
|
uint8_t second;
|
||||||
uint8_t minute;
|
uint8_t minute;
|
||||||
@@ -130,8 +115,3 @@ enum ConfigType_t {
|
|||||||
CT_CONFIG,
|
CT_CONFIG,
|
||||||
CT_SCENARIO
|
CT_SCENARIO
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BusScanner_t {
|
|
||||||
BS_I2C,
|
|
||||||
BS_ONE_WIRE
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -82,15 +82,6 @@ extern int enter_to_logging_counter;
|
|||||||
extern int scenario_line_status[40];
|
extern int scenario_line_status[40];
|
||||||
extern int lastVersion;
|
extern int lastVersion;
|
||||||
|
|
||||||
|
|
||||||
//Запрос на скарнирование шины
|
|
||||||
extern boolean busScanFlag;
|
|
||||||
|
|
||||||
//Запрос на сканирование шины, указание какую
|
|
||||||
extern BusScanner_t busToScan;
|
|
||||||
extern boolean fsCheckFlag;
|
|
||||||
|
|
||||||
|
|
||||||
//Global functions
|
//Global functions
|
||||||
// Logging
|
// Logging
|
||||||
extern void logging();
|
extern void logging();
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
#include "Bus/I2CScanner.h"
|
|
||||||
#include "Utils/PrintMessage.h"
|
|
||||||
|
|
||||||
#include <Wire.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
I2CScanner::I2CScanner(String& out) : BusScanner(TAG_I2C, out, 2){};
|
|
||||||
|
|
||||||
void I2CScanner::init() {
|
|
||||||
Wire.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean I2CScanner::syncScan() {
|
|
||||||
SerialPrint("I","module","scanning...");
|
|
||||||
size_t cnt = 0;
|
|
||||||
for (uint8_t i = 8; i < 120; i++) {
|
|
||||||
Wire.beginTransmission(i);
|
|
||||||
if (Wire.endTransmission() == 0) {
|
|
||||||
SerialPrint("I","module","found: " + i);
|
|
||||||
addResult(i, i < 119);
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
@@ -48,7 +48,6 @@ int enter_to_logging_counter;
|
|||||||
// Scenario
|
// Scenario
|
||||||
int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
int scenario_line_status[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
|
||||||
int lastVersion;
|
int lastVersion;
|
||||||
BusScanner_t busToScan;
|
|
||||||
|
|
||||||
boolean busScanFlag = false;
|
boolean busScanFlag = false;
|
||||||
boolean fsCheckFlag = false;
|
boolean fsCheckFlag = false;
|
||||||
|
|||||||
77
src/Web.cpp
77
src/Web.cpp
@@ -85,29 +85,31 @@ void web_init() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//==============================udp settings=============================================
|
//==============================udp settings=============================================
|
||||||
if (request->hasArg("udponoff")) {
|
//if (request->hasArg("udponoff")) {
|
||||||
bool value = request->getParam("udponoff")->value().toInt();
|
// bool value = request->getParam("udponoff")->value().toInt();
|
||||||
jsonWriteBool(configSetupJson, "udponoff", value);
|
// jsonWriteBool(configSetupJson, "udponoff", value);
|
||||||
saveConfig();
|
// saveConfig();
|
||||||
loadScenario();
|
// loadScenario();
|
||||||
request->send(200);
|
// request->send(200);
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
|
//if (request->hasArg("updatelist")) {
|
||||||
|
// removeFile("/dev.csv");
|
||||||
|
// addFileLn("dev.csv", "device id;device name;ip address");
|
||||||
|
// request->redirect("/?set.udp");
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//if (request->hasArg("updatepage")) {
|
||||||
|
// request->redirect("/?set.udp");
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//if (request->hasArg("devname")) {
|
||||||
|
// jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
||||||
|
// saveConfig();
|
||||||
|
// request->send(200);
|
||||||
|
//}
|
||||||
|
|
||||||
if (request->hasArg("updatelist")) {
|
|
||||||
removeFile("/dev.csv");
|
|
||||||
addFileLn("dev.csv", "device id;device name;ip address");
|
|
||||||
request->redirect("/?set.udp");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->hasArg("updatepage")) {
|
|
||||||
request->redirect("/?set.udp");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->hasArg("devname")) {
|
|
||||||
jsonWriteStr(configSetupJson, "name", request->getParam("devname")->value());
|
|
||||||
saveConfig();
|
|
||||||
request->send(200);
|
|
||||||
}
|
|
||||||
//==============================wifi settings=============================================
|
//==============================wifi settings=============================================
|
||||||
if (request->hasArg("routerssid")) {
|
if (request->hasArg("routerssid")) {
|
||||||
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
|
jsonWriteStr(configSetupJson, "routerssid", request->getParam("routerssid")->value());
|
||||||
@@ -167,7 +169,9 @@ void web_init() {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
request->send(200);
|
request->send(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================mqtt settings=============================================
|
//==============================mqtt settings=============================================
|
||||||
|
|
||||||
if (request->hasArg("mqttServer")) {
|
if (request->hasArg("mqttServer")) {
|
||||||
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
|
jsonWriteStr(configSetupJson, "mqttServer", request->getParam("mqttServer")->value());
|
||||||
saveConfig();
|
saveConfig();
|
||||||
@@ -215,30 +219,19 @@ void web_init() {
|
|||||||
request->send(200, "text/html", payload);
|
request->send(200, "text/html", payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
//==============================push settings=============================================
|
// //==============================push settings=============================================
|
||||||
#ifdef PUSH_ENABLED
|
//#ifdef PUSH_ENABLED
|
||||||
if (request->hasArg("pushingboxid")) {
|
// if (request->hasArg("pushingboxid")) {
|
||||||
jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
|
// jsonWriteStr(configSetupJson, "pushingboxid", request->getParam("pushingboxid")->value());
|
||||||
saveConfig();
|
// saveConfig();
|
||||||
request->send(200);
|
// request->send(200);
|
||||||
}
|
// }
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
//==============================utilities settings=============================================
|
//==============================utilities settings=============================================
|
||||||
if (request->hasArg(TAG_I2C)) {
|
if (request->hasArg("i2c")) {
|
||||||
busScanFlag = true;
|
|
||||||
busToScan = BS_I2C;
|
|
||||||
request->redirect("/?set.utilities");
|
request->redirect("/?set.utilities");
|
||||||
} else if (request->hasArg(TAG_ONE_WIRE)) {
|
|
||||||
busScanFlag = true;
|
|
||||||
busToScan = BS_ONE_WIRE;
|
|
||||||
if (request->hasParam(TAG_ONE_WIRE_PIN)) {
|
|
||||||
setConfigParam(TAG_ONE_WIRE_PIN, request->getParam(TAG_ONE_WIRE_PIN)->value());
|
|
||||||
}
|
|
||||||
request->redirect("/?set.utilities");
|
|
||||||
} else if (request->hasArg(TAG_ONE_WIRE_PIN)) {
|
|
||||||
setConfigParam(TAG_ONE_WIRE_PIN, request->getParam(TAG_ONE_WIRE_PIN)->value());
|
|
||||||
request->send(200);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
18
src/bus.cpp
18
src/bus.cpp
@@ -1,18 +0,0 @@
|
|||||||
#include "Bus/BusScannerFactory.h"
|
|
||||||
#include "Class/NotAsinc.h"
|
|
||||||
#include "Global.h"
|
|
||||||
|
|
||||||
void busInit() {
|
|
||||||
myNotAsincActions->add(
|
|
||||||
do_BUSSCAN, [&](void*) {
|
|
||||||
doBusScan();
|
|
||||||
},
|
|
||||||
nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void doBusScan() {
|
|
||||||
String res = "";
|
|
||||||
BusScanner* scanner = BusScannerFactory::get(configSetupJson, busToScan, res);
|
|
||||||
scanner->scan();
|
|
||||||
jsonWriteStr(configLiveJson, String(scanner->tag()), res);
|
|
||||||
}
|
|
||||||
@@ -99,9 +99,6 @@ void loop() {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef WS_enable
|
#ifdef WS_enable
|
||||||
ws.cleanupClients();
|
ws.cleanupClients();
|
||||||
#endif
|
|
||||||
#ifdef UDP_ENABLED
|
|
||||||
loopUdp();
|
|
||||||
#endif
|
#endif
|
||||||
timeNow->loop();
|
timeNow->loop();
|
||||||
MqttClient::loop();
|
MqttClient::loop();
|
||||||
|
|||||||
Reference in New Issue
Block a user