|
|
|
@ -42,18 +42,15 @@ void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
|
|
|
|
|
String str_data = (String)(char*)data; |
|
|
|
|
String head = str_data.substring(0,3); |
|
|
|
|
String body = str_data.substring(3,str_data.length()); |
|
|
|
|
|
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Serial.println("head: "+ head + " body: " + body); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if(head == "h1t"){ |
|
|
|
|
temp1_target = body.toDouble(); |
|
|
|
|
}else if(head == "h2t"){ |
|
|
|
|
temp2_target = body.toDouble(); |
|
|
|
|
} |
|
|
|
|
//Serial.println(power);
|
|
|
|
|
|
|
|
|
|
//pinMode(LED_PIN, 0);
|
|
|
|
|
//LED_handler.attach_ms(300, led_off);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -61,12 +58,16 @@ void handleWebSocketMessage(void *arg, uint8_t *data, size_t len) {
|
|
|
|
|
void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) { |
|
|
|
|
switch (type) { |
|
|
|
|
case WS_EVT_CONNECT: |
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str()); |
|
|
|
|
#endif |
|
|
|
|
temp1_target = HEAT_OFF; |
|
|
|
|
temp2_target = HEAT_OFF; |
|
|
|
|
break; |
|
|
|
|
case WS_EVT_DISCONNECT: |
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Serial.printf("WebSocket client #%u disconnected\n", client->id()); |
|
|
|
|
#endif |
|
|
|
|
temp1_target = HEAT_OFF; |
|
|
|
|
temp2_target = HEAT_OFF; |
|
|
|
|
break; |
|
|
|
@ -87,18 +88,24 @@ void web_report_handler(){
|
|
|
|
|
ws.textAll("h2c" + String(temp2_current)); |
|
|
|
|
ws.textAll("h1t" + String(temp1_target)); |
|
|
|
|
ws.textAll("h2t" + String(temp2_target)); |
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Serial.println("report temp" + String(" h1c: ") + String(temp1_current) + " h2c: " + String(temp2_current) + " h1t: " + String(temp1_target) + " h2t: " + String(temp2_target)); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wireless_setup(){ |
|
|
|
|
/*[LittleFS Init]*/ |
|
|
|
|
if(!LittleFS.begin()){ |
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Serial.println("fail init fs"); |
|
|
|
|
#endif |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*[Show All Files]*/ |
|
|
|
|
#ifdef SERIAL_DEBUG |
|
|
|
|
Dir root = LittleFS.openDir("/"); |
|
|
|
|
while (root.next()) { |
|
|
|
|
File file = root.openFile("r"); |
|
|
|
@ -108,10 +115,13 @@ void wireless_setup(){
|
|
|
|
|
Serial.println(file.size()); |
|
|
|
|
file.close(); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*[Wifi Init]*/ |
|
|
|
|
WiFi.softAP(AP_SSID, AP_PASSWD, AP_CHANNEL, 0, AP_MAX_CLIENT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*[Web Init]*/ |
|
|
|
|
ws.onEvent(onEvent); |
|
|
|
|
server.addHandler(&ws); |
|
|
|
@ -121,9 +131,11 @@ void wireless_setup(){
|
|
|
|
|
|
|
|
|
|
server.begin(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*[OTA Init]*/ |
|
|
|
|
ArduinoOTA.begin(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*[Ticker Init]*/ |
|
|
|
|
temp_reporter.attach(0.5, web_report_handler); |
|
|
|
|
} |
|
|
|
|