// pip install pyserial // MQTT JOEL GÄhwiller // Telnetstream Andrassi #include "bluetooth.h" #include #include #include #include "RFID.h" #include "logger.h" #define rxRFID 15 // COM2: 16 -- 18 #define txRFID 2 // COM2: 17 -- 19 #define GPIO6 6 const char* ssid = "coral"; const char* password = "135798642"; const char* OTApassword = "135798642"; IPAddress apIP(192, 168, 200, 1); IPAddress Gateway(192, 168, 200, 100); IPAddress MQTTserver(192, 168, 200, 2); unsigned long StartTime = millis(); WiFiClient net; MQTTClient client; RFID rfid; int loopCounter = 0; String buffer; unsigned long TimeStamp; bool readProgress; BLUETOOTH bt; void setup() { Serial.begin(115200); bt.setup(); WiFi.mode(WIFI_AP_STA); WiFi.softAPConfig(apIP, Gateway, IPAddress(255, 255, 255, 0)); WiFi.softAP(ssid, password); pinMode(rxRFID, INPUT); pinMode(txRFID, OUTPUT); Serial2.begin(57600, SERIAL_8N1,rxRFID,txRFID ); client.begin(MQTTserver, net); client.setTimeout (500); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { }); ArduinoOTA.setHostname("Coral"); ArduinoOTA.setPassword(OTApassword); ArduinoOTA.begin(); logger.setup(); buffer = ""; readProgress = false; Serial.println("END SETUP"); } void loop() { logger.loop(); bt.loop(); ArduinoOTA.handle(); // ********************** READ RFID ****************** if (!logger.serialBridge) { while (Serial2.available()) { ArduinoOTA.handle(); buffer = buffer + rfid.toHex ( Serial2.read() ); TimeStamp = millis(); readProgress = true; } if (((millis() - TimeStamp)>200) && readProgress) // ABORT WHEN TIMEOUT { if (rfid.validate (buffer)) { buffer.toUpperCase(); client.publish("tag", buffer); logger.log(5, buffer); } buffer = ""; readProgress = false; } // ************ CALCULATE LOOP TIME ************************ loopCounter++; if (loopCounter > 10000) { unsigned long delta = millis() - StartTime; char buf[50]; sprintf(buf, "Loop time: %lu - %lu - %lu", millis(), StartTime, delta); logger.log(5, buf); StartTime = millis(); loopCounter = 0; if (!client.connected()) { client.connect("coral", "public", "public"); } } } }