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 @@ 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