diff --git a/sketch/configuration.cpp b/sketch/configuration.cpp new file mode 100644 index 0000000..9a8bd9d --- /dev/null +++ b/sketch/configuration.cpp @@ -0,0 +1,53 @@ +#include "configuration.h" +#include "defines.h" + +#include +#include +#include "HT_SSD1306Wire.h" + +#include +#include +#include + +SSD1306Wire confDisplay(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED);; // addr , freq , i2c group , resolution , rst + +const char *ssid = "ModbusLoraConf"; +char password[12]; + + +void configurationSetup() { + digitalWrite(Vext,LOW); + confDisplay.init(); + confDisplay.setFont(ArialMT_Plain_10); + confDisplay.setTextAlignment(TEXT_ALIGN_LEFT); + confDisplay.clear(); + confDisplay.drawString(1, 1, "Configuration Mode starting"); + confDisplay.display(); + + memset(password, 0, sizeof(password)); + for (int i = 0; i < sizeof(password) - 1; i++) { + password[i] = random(65, 90); + } + + WiFi.softAP(ssid, password); + IPAddress myIP = WiFi.softAPIP(); + Serial.print("AP IP address: "); + Serial.println(myIP); + char buf[64]; + memset(buf, 0, sizeof(buf)); + sprintf(buf, "SSID: %s", ssid); + confDisplay.drawString(1, 15, buf); + memset(buf, 0, sizeof(buf)); + sprintf(buf, "Key: %s", password); + confDisplay.drawString(1, 30, buf); + confDisplay.display(); + + + delay(2000); + +} + + +void configurationLoop() { + +} \ No newline at end of file diff --git a/sketch/configuration.h b/sketch/configuration.h new file mode 100644 index 0000000..8eb3159 --- /dev/null +++ b/sketch/configuration.h @@ -0,0 +1,9 @@ +#ifndef _CONFIGURATION_H_ +#define _CONFIGURATION_H_ + + +void configurationSetup(); +void configurationLoop(); + + +#endif // _CONFIGURATION_H_ diff --git a/sketch/production.cpp b/sketch/production.cpp index 8c6b2c9..bca3910 100644 --- a/sketch/production.cpp +++ b/sketch/production.cpp @@ -93,6 +93,7 @@ static void prepareTxFrame( uint8_t port ) } } +RTC_DATA_ATTR bool firstrun = true; void productionSetup() { @@ -102,6 +103,12 @@ void productionSetup() { pModbusClient->begin(9600, SERIAL_8N1); Mcu.begin(); + + if(firstrun) { + LoRaWAN.displayMcuInit(); + firstrun = false; + } + deviceState = DEVICE_STATE_INIT; } @@ -122,12 +129,14 @@ void productionLoop() } case DEVICE_STATE_JOIN: { + LoRaWAN.displayJoining(); LoRaWAN.join(); break; } case DEVICE_STATE_SEND: digitalWrite(LED_BLUE, HIGH); { + LoRaWAN.displaySending(); Serial.println("sending"); prepareTxFrame( appPort ); LoRaWAN.send(); @@ -145,6 +154,7 @@ void productionLoop() } case DEVICE_STATE_SLEEP: { + LoRaWAN.displayAck(); LoRaWAN.sleep(loraWanClass); break; } diff --git a/sketch/sketch.ino b/sketch/sketch.ino index 3766990..204add3 100644 --- a/sketch/sketch.ino +++ b/sketch/sketch.ino @@ -2,12 +2,13 @@ #include "defines.h" #include "config.h" #include "production.h" +#include "configuration.h" // from config.cpp extern config_t myConfig; -bool productionMode = true; +bool productionMode = false; void setup() { pinMode(LED_BLUE, OUTPUT); @@ -23,6 +24,8 @@ void setup() { if (productionMode) { productionSetup(); + } else { + configurationSetup(); } } @@ -30,5 +33,7 @@ void loop() { if (productionMode) { productionLoop(); + } else { + configurationLoop(); } }