mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Some changes
This commit is contained in:
@@ -43,7 +43,7 @@
|
||||
},
|
||||
{
|
||||
"type": "h4",
|
||||
"title": "LittleFS version: 240"
|
||||
"title": "LittleFS version: 241"
|
||||
},
|
||||
{
|
||||
"type": "hr"
|
||||
|
||||
@@ -160,21 +160,23 @@ class LineParsing {
|
||||
}
|
||||
|
||||
void createWidgetClass(String descr, String page, String order, String filename, String topic) {
|
||||
String buf = "{}";
|
||||
if (!loadWidgetClass(filename, buf)) {
|
||||
return;
|
||||
}
|
||||
if (filename != "na") {
|
||||
String buf = "{}";
|
||||
if (!loadWidgetClass(filename, buf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
jsonWriteStr(buf, "page", page);
|
||||
jsonWriteStr(buf, "order", order);
|
||||
jsonWriteStr(buf, "descr", descr);
|
||||
jsonWriteStr(buf, "topic", prex + "/" + topic);
|
||||
jsonWriteStr(buf, "page", page);
|
||||
jsonWriteStr(buf, "order", order);
|
||||
jsonWriteStr(buf, "descr", descr);
|
||||
jsonWriteStr(buf, "topic", prex + "/" + topic);
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
all_widgets += widget + "\r\n";
|
||||
all_widgets += widget + "\r\n";
|
||||
#else
|
||||
addFileLn("layout.txt", buf);
|
||||
addFileLn("layout.txt", buf);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool loadWidgetClass(const String& filename, String& buf) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
//=================Firmeare=================
|
||||
#define FIRMWARE_NAME "esp8266-iotm"
|
||||
#define FIRMWARE_VERSION 240
|
||||
#define FIRMWARE_VERSION 241
|
||||
#define FLASH_4MB true
|
||||
|
||||
//=================System===================
|
||||
@@ -25,7 +25,7 @@
|
||||
//#define WEBSOCKET_ENABLED
|
||||
//#define LAYOUT_IN_RAM
|
||||
//#define UDP_ENABLED
|
||||
#define SSDP_EN
|
||||
//#define SSDP_EN
|
||||
|
||||
//=========Sensors enable/disable===========
|
||||
#define TANK_LEVEL_SAMPLES 10
|
||||
|
||||
@@ -128,9 +128,9 @@ extern void createChart(String widget_name, String page_name, String page_number
|
||||
extern void pushControl();
|
||||
|
||||
// UDP
|
||||
extern void udpInit();
|
||||
extern void do_udp_data_parse();
|
||||
extern void do_mqtt_send_settings_to_udp();
|
||||
//extern void udpInit();
|
||||
//extern void do_udp_data_parse();
|
||||
//extern void do_mqtt_send_settings_to_udp();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -44,5 +44,5 @@ extern void bmp280ReadingTemp();
|
||||
extern void bmp280Press();
|
||||
extern void bmp280ReadingPress();
|
||||
|
||||
extern void modbus();
|
||||
extern void modbusReading();
|
||||
//extern void modbus();
|
||||
//extern void modbusReading();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "ESPAsyncUDP.h"
|
||||
extern AsyncUDP asyncUdp;
|
||||
extern void asyncUdpInit();
|
||||
extern String uint8tToString(uint8_t* data, size_t len);
|
||||
extern bool udpPacketValidation(String& data);
|
||||
extern void udpPacketParse(String& data);
|
||||
//#pragma once
|
||||
//#include "ESPAsyncUDP.h"
|
||||
//extern AsyncUDP asyncUdp;
|
||||
//extern void asyncUdpInit();
|
||||
//extern String uint8tToString(uint8_t* data, size_t len);
|
||||
//extern bool udpPacketValidation(String& data);
|
||||
//extern void udpPacketParse(String& data);
|
||||
@@ -1,83 +1,83 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <ModbusMaster.h>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
|
||||
ModbusMaster modbus1;
|
||||
SoftwareSerial uart(13, 12); // RX, TX
|
||||
|
||||
class SensorModbusClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorModbusClass() : SensorConvertingClass(){};
|
||||
|
||||
void SensorModbusInit() {
|
||||
uart.begin(9600);
|
||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
sensorReadingMap += _key + " " + _addr + " " + _reg + ",";
|
||||
Serial.println(sensorReadingMap);
|
||||
}
|
||||
|
||||
void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||
int value;
|
||||
|
||||
modbus1.begin(slaveAddress, uart);
|
||||
uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||
if (getResultMsg(&modbus1, reqisterValue)) {
|
||||
reqisterValue = modbus1.getResponseBuffer(0);
|
||||
value = reqisterValue;
|
||||
} else {
|
||||
value = NULL;
|
||||
}
|
||||
|
||||
int valueFl = this->correction(key, value);
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("I sensor '" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
||||
}
|
||||
|
||||
bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||
String tmpstr;
|
||||
switch (result) {
|
||||
case modbus1->ku8MBSuccess:
|
||||
return true;
|
||||
tmpstr += "Ok";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalFunction:
|
||||
tmpstr += "Illegal Function";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalDataAddress:
|
||||
tmpstr += "Illegal Data Address";
|
||||
break;
|
||||
case modbus1->ku8MBIllegalDataValue:
|
||||
tmpstr += "Illegal Data Value";
|
||||
break;
|
||||
case modbus1->ku8MBSlaveDeviceFailure:
|
||||
tmpstr += "Slave Device Failure";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidSlaveID:
|
||||
tmpstr += "Invalid Slave ID";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidFunction:
|
||||
tmpstr += "Invalid Function";
|
||||
break;
|
||||
case modbus1->ku8MBResponseTimedOut:
|
||||
tmpstr += "Response Timed Out";
|
||||
break;
|
||||
case modbus1->ku8MBInvalidCRC:
|
||||
tmpstr += "Invalid CRC";
|
||||
break;
|
||||
default:
|
||||
tmpstr += "Unknown error: " + String(result);
|
||||
break;
|
||||
}
|
||||
SerialPrint("I", "Modbus", tmpstr);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
extern SensorModbusClass mySensorModbus;
|
||||
//#pragma once
|
||||
//#include <Arduino.h>
|
||||
//#include <ModbusMaster.h>
|
||||
//#include <SoftwareSerial.h>
|
||||
//
|
||||
//#include "Class/LineParsing.h"
|
||||
//#include "Global.h"
|
||||
//#include "items/SensorConvertingClass.h"
|
||||
//
|
||||
//ModbusMaster modbus1;
|
||||
//SoftwareSerial uart(13, 12); // RX, TX
|
||||
//
|
||||
//class SensorModbusClass : public SensorConvertingClass {
|
||||
// public:
|
||||
// SensorModbusClass() : SensorConvertingClass(){};
|
||||
//
|
||||
// void SensorModbusInit() {
|
||||
// uart.begin(9600);
|
||||
// jsonWriteStr(configOptionJson, _key + "_map", _map);
|
||||
// jsonWriteStr(configOptionJson, _key + "_с", _c);
|
||||
// sensorReadingMap += _key + " " + _addr + " " + _reg + ",";
|
||||
// Serial.println(sensorReadingMap);
|
||||
// }
|
||||
//
|
||||
// void SensorModbusRead(String key, uint8_t slaveAddress, uint16_t regAddress) {
|
||||
// int value;
|
||||
//
|
||||
// modbus1.begin(slaveAddress, uart);
|
||||
// uint16_t reqisterValue = modbus1.readHoldingRegisters(regAddress, 1);
|
||||
// if (getResultMsg(&modbus1, reqisterValue)) {
|
||||
// reqisterValue = modbus1.getResponseBuffer(0);
|
||||
// value = reqisterValue;
|
||||
// } else {
|
||||
// value = NULL;
|
||||
// }
|
||||
//
|
||||
// int valueFl = this->correction(key, value);
|
||||
// eventGen(key, "");
|
||||
// jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
// MqttClient::publishStatus(key, String(valueFl));
|
||||
// Serial.println("I sensor '" + key + "' data: " + String(valueFl) + ", Slave dev addr: " + String(slaveAddress) + ", Register: " + String(regAddress));
|
||||
// }
|
||||
//
|
||||
// bool getResultMsg(ModbusMaster* modbus1, uint16_t result) {
|
||||
// String tmpstr;
|
||||
// switch (result) {
|
||||
// case modbus1->ku8MBSuccess:
|
||||
// return true;
|
||||
// tmpstr += "Ok";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalFunction:
|
||||
// tmpstr += "Illegal Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataAddress:
|
||||
// tmpstr += "Illegal Data Address";
|
||||
// break;
|
||||
// case modbus1->ku8MBIllegalDataValue:
|
||||
// tmpstr += "Illegal Data Value";
|
||||
// break;
|
||||
// case modbus1->ku8MBSlaveDeviceFailure:
|
||||
// tmpstr += "Slave Device Failure";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidSlaveID:
|
||||
// tmpstr += "Invalid Slave ID";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidFunction:
|
||||
// tmpstr += "Invalid Function";
|
||||
// break;
|
||||
// case modbus1->ku8MBResponseTimedOut:
|
||||
// tmpstr += "Response Timed Out";
|
||||
// break;
|
||||
// case modbus1->ku8MBInvalidCRC:
|
||||
// tmpstr += "Invalid CRC";
|
||||
// break;
|
||||
// default:
|
||||
// tmpstr += "Unknown error: " + String(result);
|
||||
// break;
|
||||
// }
|
||||
// SerialPrint("I", "Modbus", tmpstr);
|
||||
// return false;
|
||||
// }
|
||||
//};
|
||||
//extern SensorModbusClass mySensorModbus;
|
||||
@@ -43,7 +43,7 @@ void cmd_init() {
|
||||
sCmd.addCommand("bmp280-temp", bmp280Temp);
|
||||
sCmd.addCommand("bmp280-press", bmp280Press);
|
||||
|
||||
sCmd.addCommand("modbus", modbus);
|
||||
//sCmd.addCommand("modbus", modbus);
|
||||
|
||||
handle_time_init();
|
||||
}
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
#include "RemoteOrdersUdp.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
AsyncUDP asyncUdp;
|
||||
|
||||
void asyncUdpInit() {
|
||||
//if (asyncUdp.listen(1234)) {
|
||||
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 1234)) {
|
||||
asyncUdp.onPacket([](AsyncUDPPacket packet) {
|
||||
|
||||
//Serial.print("UDP Packet Type: ");
|
||||
//Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
//
|
||||
//Serial.print(", From: ");
|
||||
//Serial.print(packet.remoteIP());
|
||||
//Serial.print(":");
|
||||
//Serial.print(packet.remotePort());
|
||||
//
|
||||
//Serial.print(", To: ");
|
||||
//Serial.print(packet.localIP());
|
||||
//Serial.print(":");
|
||||
//Serial.print(packet.localPort());
|
||||
//
|
||||
//Serial.print(", Length: ");
|
||||
//Serial.print(packet.length());
|
||||
//
|
||||
//Serial.print(", Data: ");
|
||||
//Serial.write(packet.data(), packet.length());
|
||||
|
||||
String data = uint8tToString(packet.data(), packet.length());
|
||||
Serial.print("[i] [udp] Packet received: '");
|
||||
Serial.print(data);
|
||||
if (udpPacketValidation(data)) {
|
||||
udpPacketParse(data);
|
||||
//Serial.println("', Packet valid");
|
||||
} else {
|
||||
//Serial.println("', Packet invalid");
|
||||
}
|
||||
|
||||
//reply to the client
|
||||
|
||||
packet.printf("Got %u bytes of data", packet.length());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String uint8tToString(uint8_t* data, size_t len) {
|
||||
String ret;
|
||||
while (len--) {
|
||||
ret += (char)*data++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool udpPacketValidation(String& data) {
|
||||
if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//iotm;chipid;button-out-1_1
|
||||
void udpPacketParse(String& data) {
|
||||
data = selectFromMarkerToMarker(data, ";", 2);
|
||||
data.replace("_", " ");
|
||||
orderBuf += data + ",";
|
||||
}
|
||||
//#include "RemoteOrdersUdp.h"
|
||||
//
|
||||
//#include <Arduino.h>
|
||||
//
|
||||
//#include "Global.h"
|
||||
//
|
||||
//AsyncUDP asyncUdp;
|
||||
//
|
||||
//void asyncUdpInit() {
|
||||
// //if (asyncUdp.listen(1234)) {
|
||||
// if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 1234)) {
|
||||
// asyncUdp.onPacket([](AsyncUDPPacket packet) {
|
||||
//
|
||||
// //Serial.print("UDP Packet Type: ");
|
||||
// //Serial.print(packet.isBroadcast() ? "Broadcast" : packet.isMulticast() ? "Multicast" : "Unicast");
|
||||
// //
|
||||
// //Serial.print(", From: ");
|
||||
// //Serial.print(packet.remoteIP());
|
||||
// //Serial.print(":");
|
||||
// //Serial.print(packet.remotePort());
|
||||
// //
|
||||
// //Serial.print(", To: ");
|
||||
// //Serial.print(packet.localIP());
|
||||
// //Serial.print(":");
|
||||
// //Serial.print(packet.localPort());
|
||||
// //
|
||||
// //Serial.print(", Length: ");
|
||||
// //Serial.print(packet.length());
|
||||
// //
|
||||
// //Serial.print(", Data: ");
|
||||
// //Serial.write(packet.data(), packet.length());
|
||||
//
|
||||
// String data = uint8tToString(packet.data(), packet.length());
|
||||
// Serial.print("[i] [udp] Packet received: '");
|
||||
// Serial.print(data);
|
||||
// if (udpPacketValidation(data)) {
|
||||
// udpPacketParse(data);
|
||||
// //Serial.println("', Packet valid");
|
||||
// } else {
|
||||
// //Serial.println("', Packet invalid");
|
||||
// }
|
||||
//
|
||||
// //reply to the client
|
||||
//
|
||||
// packet.printf("Got %u bytes of data", packet.length());
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//String uint8tToString(uint8_t* data, size_t len) {
|
||||
// String ret;
|
||||
// while (len--) {
|
||||
// ret += (char)*data++;
|
||||
// }
|
||||
// return ret;
|
||||
//}
|
||||
//
|
||||
//bool udpPacketValidation(String& data) {
|
||||
// if (data.indexOf("iotm;") != -1 && data.indexOf(getChipId()) != -1) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////iotm;chipid;button-out-1_1
|
||||
//void udpPacketParse(String& data) {
|
||||
// data = selectFromMarkerToMarker(data, ";", 2);
|
||||
// data.replace("_", " ");
|
||||
// orderBuf += data + ",";
|
||||
//}
|
||||
@@ -1,23 +1,23 @@
|
||||
#include "items/SensorModbusClass.h"
|
||||
|
||||
#include "ItemsCmd.h"
|
||||
//#ifdef SensorModbusEnabled
|
||||
//=========================================Модуль modbus===================================================================================
|
||||
//modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorModbusClass mySensorModbus;
|
||||
|
||||
void modbus() {
|
||||
mySensorModbus.update();
|
||||
String key = mySensorModbus.gkey();
|
||||
sCmd.addCommand(key.c_str(), modbusReading);
|
||||
mySensorModbus.SensorModbusInit();
|
||||
mySensorModbus.clear();
|
||||
}
|
||||
void modbusReading() {
|
||||
String key = sCmd.order();
|
||||
String addr = sCmd.next();
|
||||
String regaddr = sCmd.next();
|
||||
mySensorModbus.SensorModbusRead(key, addr.toInt(), regaddr.toInt());
|
||||
}
|
||||
//#endif
|
||||
//#include "items/SensorModbusClass.h"
|
||||
//
|
||||
//#include "ItemsCmd.h"
|
||||
////#ifdef SensorModbusEnabled
|
||||
////=========================================Модуль modbus===================================================================================
|
||||
////modbus;id;anydata;Сенсоры;Температура;order;addr[1];regaddr[0];c[1]
|
||||
////=========================================================================================================================================
|
||||
//SensorModbusClass mySensorModbus;
|
||||
//
|
||||
//void modbus() {
|
||||
// mySensorModbus.update();
|
||||
// String key = mySensorModbus.gkey();
|
||||
// sCmd.addCommand(key.c_str(), modbusReading);
|
||||
// mySensorModbus.SensorModbusInit();
|
||||
// mySensorModbus.clear();
|
||||
//}
|
||||
//void modbusReading() {
|
||||
// String key = sCmd.order();
|
||||
// String addr = sCmd.next();
|
||||
// String regaddr = sCmd.next();
|
||||
// mySensorModbus.SensorModbusRead(key, addr.toInt(), regaddr.toInt());
|
||||
//}
|
||||
////#endif
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Utils/Timings.h"
|
||||
#include "Utils\WebUtils.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
#include "RemoteOrdersUdp.h"
|
||||
//#include "RemoteOrdersUdp.h"
|
||||
#include "Bus.h"
|
||||
|
||||
void not_async_actions();
|
||||
@@ -72,8 +72,8 @@ void setup() {
|
||||
SerialPrint("I","Stat","Stat Init");
|
||||
initSt();
|
||||
|
||||
SerialPrint("I","UDP","Udp Init");
|
||||
asyncUdpInit();
|
||||
//SerialPrint("I","UDP","Udp Init");
|
||||
//asyncUdpInit();
|
||||
|
||||
SerialPrint("I","Bus","Bus Init");
|
||||
busInit();
|
||||
|
||||
Reference in New Issue
Block a user