mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
upd /localota, modbusAsync
This commit is contained in:
@@ -10,6 +10,7 @@ extern void handleFileUpload();
|
|||||||
extern void handleFileDelete();
|
extern void handleFileDelete();
|
||||||
extern void handleFileCreate();
|
extern void handleFileCreate();
|
||||||
extern void handleLocalOTA();
|
extern void handleLocalOTA();
|
||||||
|
extern void handleLocalOTA_Handler();
|
||||||
extern void handleFileList();
|
extern void handleFileList();
|
||||||
//void printDirectory(File dir, String& out);
|
//void printDirectory(File dir, String& out);
|
||||||
extern void handleStatus();
|
extern void handleStatus();
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ void standWebServerInit() {
|
|||||||
|
|
||||||
HTTP.on("/localota", HTTP_GET, handleLocalOTA);
|
HTTP.on("/localota", HTTP_GET, handleLocalOTA);
|
||||||
|
|
||||||
|
HTTP.on("/localota_handler", HTTP_GET, handleLocalOTA_Handler);
|
||||||
|
|
||||||
// Default handler for all URIs not defined above
|
// Default handler for all URIs not defined above
|
||||||
// Use it to read files from filesystem
|
// Use it to read files from filesystem
|
||||||
HTTP.onNotFound(handleNotFound);
|
HTTP.onNotFound(handleNotFound);
|
||||||
@@ -159,7 +161,12 @@ void handleStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleLocalOTA() {
|
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
|
#ifdef ESP32
|
||||||
|
|||||||
@@ -101,7 +101,7 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"defActive": true,
|
"defActive": false,
|
||||||
"usedLibs": {
|
"usedLibs": {
|
||||||
"esp32*": [],
|
"esp32*": [],
|
||||||
"esp82*": []
|
"esp82*": []
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ public:
|
|||||||
modBus_Token_count++;
|
modBus_Token_count++;
|
||||||
_token = modBus_Token_count;
|
_token = modBus_Token_count;
|
||||||
MBNoneMap[_token] = this;
|
MBNoneMap[_token] = this;
|
||||||
|
Serial.printf("Добавлен нода/токен: %s - %d\n", getID(), _token);
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval()
|
void doByInterval()
|
||||||
@@ -129,11 +130,13 @@ public:
|
|||||||
if (_func == 0x02) // coil
|
if (_func == 0x02) // coil
|
||||||
{
|
{
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
response.get(3, val);
|
//response.get(3, val);
|
||||||
regEvent(val, "ModbusNode");
|
//regEvent((float)val, "ModbusNode");
|
||||||
CoilData cd(_countReg);
|
CoilData cd(_countReg);
|
||||||
cd.set(0, _countReg, (uint8_t *)response.data() + 3);
|
cd.set(0, _countReg, (uint8_t *)response.data() + 3);
|
||||||
cd.print("Received : ", Serial);
|
cd.print("Received : ", Serial);
|
||||||
|
val = cd[0];
|
||||||
|
regEvent(val, "ModbusNode");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -151,23 +154,25 @@ public:
|
|||||||
response.get(3, val1);
|
response.get(3, val1);
|
||||||
response.get(4, val2);
|
response.get(4, val2);
|
||||||
long val = val1 | val2 << 16;
|
long val = val1 | val2 << 16;
|
||||||
regEvent(val, "ModbusNode");
|
regEvent((float)val, "ModbusNode");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
response.get(3, 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
|
// Define an onData handler function to receive the regular responses
|
||||||
// Arguments are received response message and the request's token
|
// Arguments are received response message and the request's token
|
||||||
void handleModBusData(ModbusMessage response, uint32_t token)
|
void handleModBusData(ModbusMessage response, uint32_t token)
|
||||||
@@ -189,6 +194,10 @@ void handleModBusData(ModbusMessage response, uint32_t token)
|
|||||||
{
|
{
|
||||||
MBNoneMap[token]->parseMB(response);
|
MBNoneMap[token]->parseMB(response);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.printf("Токен/Нода не найден: %d\n", token);
|
||||||
|
}
|
||||||
// modBus_data_ready = true;
|
// modBus_data_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +437,17 @@ public:
|
|||||||
// next set a single coil at 8
|
// next set a single coil at 8
|
||||||
Serial.printf("sending request with token %d\n", _token);
|
Serial.printf("sending request with token %d\n", _token);
|
||||||
Error err;
|
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)
|
if (err != SUCCESS)
|
||||||
{
|
{
|
||||||
ModbusError e(err);
|
ModbusError e(err);
|
||||||
@@ -453,6 +472,7 @@ public:
|
|||||||
// node.setTransmitBuffer(0, state);
|
// node.setTransmitBuffer(0, state);
|
||||||
// result = node.writeMultipleRegisters(_reg, count);
|
// result = node.writeMultipleRegisters(_reg, count);
|
||||||
// node.clearTransmitBuffer();
|
// node.clearTransmitBuffer();
|
||||||
|
Serial.printf("NOT SUPPORTED!\n");
|
||||||
if (_debug)
|
if (_debug)
|
||||||
{
|
{
|
||||||
SerialPrint("I", "ModbusClientAsync", "writeSingleCoil, addr: " + String((uint8_t)_addr, HEX) + ", regStr: " + _regStr + ", reg: " + String(_reg, HEX) + ", state: " + String(state));
|
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)
|
void *getAPI_ModbusRTUasync(String subtype, String param)
|
||||||
{
|
{
|
||||||
if (subtype == F("mbNode"))
|
if (subtype == F("mbNode"))
|
||||||
|
|||||||
Reference in New Issue
Block a user