upd /localota, modbusAsync

This commit is contained in:
Mit4el
2025-02-05 20:33:05 +03:00
parent 959315b86e
commit 10b1adb5a5
4 changed files with 39 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ extern void handleFileUpload();
extern void handleFileDelete();
extern void handleFileCreate();
extern void handleLocalOTA();
extern void handleLocalOTA_Handler();
extern void handleFileList();
//void printDirectory(File dir, String& out);
extern void handleStatus();

View File

@@ -91,6 +91,8 @@ void standWebServerInit() {
HTTP.on("/localota", HTTP_GET, handleLocalOTA);
HTTP.on("/localota_handler", HTTP_GET, handleLocalOTA_Handler);
// Default handler for all URIs not defined above
// Use it to read files from filesystem
HTTP.onNotFound(handleNotFound);
@@ -159,7 +161,12 @@ void handleStatus() {
}
void handleLocalOTA() {
upgrade_firmware(3,"");
String page = "<form action='/localota' method='POST'><label for='server'>Server Address:</label><input type='text' name='server' value='http://192.168.1.2:5500'><input type='submit' value='Update'></form>";
HTTP.send(200, "text/html", page);}
void handleLocalOTA_Handler() {
String serverValue = HTTP.arg("server");
upgrade_firmware(3,serverValue);
}
#ifdef ESP32

View File

@@ -101,7 +101,7 @@
}
]
},
"defActive": true,
"defActive": false,
"usedLibs": {
"esp32*": [],
"esp82*": []

View File

@@ -66,6 +66,7 @@ public:
modBus_Token_count++;
_token = modBus_Token_count;
MBNoneMap[_token] = this;
Serial.printf("Добавлен нода/токен: %s - %d\n", getID(), _token);
}
void doByInterval()
@@ -129,11 +130,13 @@ public:
if (_func == 0x02) // coil
{
uint16_t val;
response.get(3, val);
regEvent(val, "ModbusNode");
//response.get(3, val);
//regEvent((float)val, "ModbusNode");
CoilData cd(_countReg);
cd.set(0, _countReg, (uint8_t *)response.data() + 3);
cd.print("Received : ", Serial);
val = cd[0];
regEvent(val, "ModbusNode");
}
else
{
@@ -151,23 +154,25 @@ public:
response.get(3, val1);
response.get(4, val2);
long val = val1 | val2 << 16;
regEvent(val, "ModbusNode");
regEvent((float)val, "ModbusNode");
}
else
{
uint16_t val;
response.get(3, val);
regEvent(val, "ModbusNode");
regEvent((float)val, "ModbusNode");
}
}
}
}
}
~ModbusNode() {};
~ModbusNode()
{
MBNoneMap.erase(_token);
};
};
// Define an onData handler function to receive the regular responses
// Arguments are received response message and the request's token
void handleModBusData(ModbusMessage response, uint32_t token)
@@ -189,6 +194,10 @@ void handleModBusData(ModbusMessage response, uint32_t token)
{
MBNoneMap[token]->parseMB(response);
}
else
{
Serial.printf("Токен/Нода не найден: %d\n", token);
}
// modBus_data_ready = true;
}
@@ -428,7 +437,17 @@ public:
// next set a single coil at 8
Serial.printf("sending request with token %d\n", _token);
Error err;
err = MB->addRequest(_token, _addr, WRITE_COIL, _reg, state);
ModbusMessage msg;
if (state)
{
msg.setMessage(_addr, WRITE_COIL, _reg, 0xFF00);
err = MB->addRequest(msg, _token);
}
else
{
//msg.setMessage(_addr, WRITE_COIL, _reg, 0x0000);
err = MB->addRequest(_token, _addr, WRITE_COIL, _reg, 0);
}
if (err != SUCCESS)
{
ModbusError e(err);
@@ -453,6 +472,7 @@ public:
// node.setTransmitBuffer(0, state);
// result = node.writeMultipleRegisters(_reg, count);
// node.clearTransmitBuffer();
Serial.printf("NOT SUPPORTED!\n");
if (_debug)
{
SerialPrint("I", "ModbusClientAsync", "writeSingleCoil, addr: " + String((uint8_t)_addr, HEX) + ", regStr: " + _regStr + ", reg: " + String(_reg, HEX) + ", state: " + String(state));
@@ -506,8 +526,6 @@ public:
};
};
void *getAPI_ModbusRTUasync(String subtype, String param)
{
if (subtype == F("mbNode"))