start configuration stuff
This commit is contained in:
53
sketch/configuration.cpp
Normal file
53
sketch/configuration.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "configuration.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <Wire.h>
|
||||
#include "HT_SSD1306Wire.h"
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiAP.h>
|
||||
|
||||
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() {
|
||||
|
||||
}
|
9
sketch/configuration.h
Normal file
9
sketch/configuration.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _CONFIGURATION_H_
|
||||
#define _CONFIGURATION_H_
|
||||
|
||||
|
||||
void configurationSetup();
|
||||
void configurationLoop();
|
||||
|
||||
|
||||
#endif // _CONFIGURATION_H_
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user