mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-29 07:32:18 +03:00
logging and udp
This commit is contained in:
@@ -47,7 +47,7 @@ String logging_value_names_list;
|
||||
int enter_to_logging_counter;
|
||||
|
||||
// Upgrade
|
||||
String serverIP = "http://206.189.49.244";
|
||||
String serverIP;
|
||||
|
||||
// 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};
|
||||
|
||||
@@ -14,6 +14,8 @@ void loadConfig() {
|
||||
prex = jsonReadStr(configSetupJson, "mqttPrefix") + "/" + chipId;
|
||||
|
||||
Serial.println(configSetupJson);
|
||||
|
||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||
}
|
||||
|
||||
void all_init() {
|
||||
|
||||
@@ -47,6 +47,8 @@ void cmd_init() {
|
||||
|
||||
sCmd.addCommand("uptime", sysUptime);
|
||||
|
||||
sCmd.addCommand("logging", logging);
|
||||
|
||||
handle_time_init();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ void sendLogData(String file, String topic);
|
||||
#ifdef LOGGING_ENABLED
|
||||
//===============================================Логирование============================================================
|
||||
//logging temp1 1 10 Температура Датчики 2
|
||||
void logging() {
|
||||
/*void logging2() {
|
||||
String value_name = sCmd.next();
|
||||
String period_min = sCmd.next();
|
||||
String maxCount = sCmd.next();
|
||||
@@ -67,12 +67,12 @@ void logging() {
|
||||
},
|
||||
nullptr, false);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/*
|
||||
* Удаление стрых данных и запись новых
|
||||
*/
|
||||
void deleteOldDate(const String filename, size_t max_lines_cnt, String payload) {
|
||||
/*void deleteOldDate(const String filename, size_t max_lines_cnt, String payload) {
|
||||
String log_date = readFile(filename, 5120);
|
||||
size_t lines_cnt = itemsCount(log_date, "\r\n");
|
||||
|
||||
@@ -94,7 +94,7 @@ void deleteOldDate(const String filename, size_t max_lines_cnt, String payload)
|
||||
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
//=========================================Выбор какие данные отправлять==================================================================
|
||||
void choose_log_date_and_send() {
|
||||
|
||||
@@ -1,71 +1,70 @@
|
||||
//#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"
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
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 + ",";
|
||||
}
|
||||
#endif
|
||||
@@ -200,6 +200,14 @@ void web_init() {
|
||||
myNotAsyncActions->make(do_BUSSCAN);
|
||||
request->redirect("/?set.utilities");
|
||||
}
|
||||
|
||||
//==============================developer settings=============================================
|
||||
if (request->hasArg("serverip")) {
|
||||
jsonWriteStr(configSetupJson, "serverip", request->getParam("serverip")->value());
|
||||
saveConfig();
|
||||
serverIP = jsonReadStr(configSetupJson, "serverip");
|
||||
request->send(200);
|
||||
}
|
||||
});
|
||||
|
||||
//==============================list of items=====================================================
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
#include "items/LoggingClass.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "ItemsCmd.h"
|
||||
|
||||
LoggingClass::LoggingClass(unsigned long period, unsigned int maxPoints, String key) {
|
||||
_period = period;
|
||||
_period = period * 1000;
|
||||
_maxPoints = maxPoints;
|
||||
_key = key;
|
||||
}
|
||||
@@ -17,7 +23,6 @@ void LoggingClass::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LoggingClass::addNewDelOldData(const String filename, size_t maxPoints, String payload) {
|
||||
String logData = readFile(filename, 5120);
|
||||
size_t lines_cnt = itemsCount(logData, "\r\n");
|
||||
@@ -28,18 +33,33 @@ void LoggingClass::addNewDelOldData(const String filename, size_t maxPoints, Str
|
||||
removeFile(filename);
|
||||
lines_cnt = 0;
|
||||
}
|
||||
|
||||
if (lines_cnt > maxPoints) {
|
||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
|
||||
writeFile(filename, logData);
|
||||
}
|
||||
} else {
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
|
||||
|
||||
if (payload != "") {
|
||||
if (lines_cnt > maxPoints) {
|
||||
logData = deleteBeforeDelimiter(logData, "\r\n");
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
logData += timeNow->getTimeUnix() + " " + payload + "\r\n";
|
||||
writeFile(filename, logData);
|
||||
}
|
||||
} else {
|
||||
if (timeNow->hasTimeSynced()) {
|
||||
addFileLn(filename, timeNow->getTimeUnix() + " " + payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MyLoggingVector* myLogging = nullptr;
|
||||
MyLoggingVector* myLogging = nullptr;
|
||||
|
||||
void logging() {
|
||||
myLineParsing.update();
|
||||
String value = myLineParsing.gvalue();
|
||||
String interv = myLineParsing.gint();
|
||||
String maxcnt = myLineParsing.gmaxcnt();
|
||||
myLineParsing.clear();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myLogging = new MyLoggingVector();
|
||||
firstTime = false;
|
||||
myLogging->push_back(LoggingClass(interv.toInt(), maxcnt.toInt(), value));
|
||||
}
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -14,7 +14,7 @@
|
||||
#include "Utils/WebUtils.h"
|
||||
#include "items/ButtonInClass.h"
|
||||
#include "items/LoggingClass.h"
|
||||
//#include "RemoteOrdersUdp.h"
|
||||
#include "RemoteOrdersUdp.h"
|
||||
#include "Bus.h"
|
||||
|
||||
void not_async_actions();
|
||||
@@ -74,9 +74,11 @@ void setup() {
|
||||
|
||||
SerialPrint("I", "Stat", "Stat Init");
|
||||
initSt();
|
||||
|
||||
//SerialPrint("I","UDP","Udp Init");
|
||||
//asyncUdpInit();
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
SerialPrint("I","UDP","Udp Init");
|
||||
asyncUdpInit();
|
||||
#endif
|
||||
|
||||
SerialPrint("I", "Bus", "Bus Init");
|
||||
busInit();
|
||||
@@ -97,8 +99,8 @@ void setup() {
|
||||
just_load = false;
|
||||
initialized = true; //this second POST makes the data to be processed (you don't need to connect as "keep-alive" for that to work)
|
||||
|
||||
myLogging = new MyLoggingVector();
|
||||
myLogging->push_back(LoggingClass(30000, 10, "analog-adc-1"));
|
||||
//myLogging = new MyLoggingVector();
|
||||
//myLogging->push_back(LoggingClass(30000, 10, "analog-adc-1"));
|
||||
//myLogging->push_back(LoggingClass(10000, 1, "10 sec"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user