commit f5c28f3c641e1ff9ca17b0cd13a2974dfe00897d Author: Petr KracĂ­k Date: Tue Jun 11 23:38:48 2019 +0200 Initial commit diff --git a/ZPA_elektromer_UARTtest.ino b/ZPA_elektromer_UARTtest.ino new file mode 100644 index 0000000..b890fca --- /dev/null +++ b/ZPA_elektromer_UARTtest.ino @@ -0,0 +1,101 @@ +#include +#include +#include + +const char* host = "zpaesp32"; +const char* ssid = "..."; +const char* password = "..."; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + WiFi.mode(WIFI_STA); + + WiFi.begin(ssid, password); + while (WiFi.waitForConnectResult() != WL_CONNECTED) { + Serial.println("Connection Failed! Rebooting..."); + delay(5000); + ESP.restart(); + } + + ArduinoOTA + .onStart([]() { + String type; + if (ArduinoOTA.getCommand() == U_FLASH) + type = "sketch"; + else // U_SPIFFS + type = "filesystem"; + + // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end() + Serial.println("Start updating " + type); + }) + .onEnd([]() { + Serial.println("\nEnd"); + }) + .onProgress([](unsigned int progress, unsigned int total) { + Serial.printf("Progress: %u%%\r", (progress / (total / 100))); + }) + .onError([](ota_error_t error) { + Serial.printf("Error[%u]: ", error); + if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); + else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); + else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); + else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); + else if (error == OTA_END_ERROR) Serial.println("End Failed"); + }); + + ArduinoOTA.begin(); + + Serial2.begin(300, SERIAL_7E1, 36, 4); + + Serial.println("Test ZPA elektro"); + + + Serial.println("Ready"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + +} + +void loop() { + // put your main code here, to run repeatedly: + ArduinoOTA.handle(); + + + if (Serial2.available()) { + char r = Serial2.read(); + + if (r == 0x02) { + Serial.print(""); + return; + } + + if (r == 0x03) { + Serial.print(""); + return; + } + + Serial.write(r); + } + + + if (Serial.available()) { + char r = Serial.read(); + + if (r == 'R') { + Serial.println("Requesting data"); + Serial2.print("/?!\r\n"); + return; + } + + if (r == 'C') { + Serial.println("Trying change baudrate"); + Serial2.write(0x06); + Serial2.print("030\r\n"); + return; + } + + Serial2.write(r); + } + +}