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() {
|
void productionSetup() {
|
||||||
@ -102,6 +103,12 @@ void productionSetup() {
|
|||||||
pModbusClient->begin(9600, SERIAL_8N1);
|
pModbusClient->begin(9600, SERIAL_8N1);
|
||||||
|
|
||||||
Mcu.begin();
|
Mcu.begin();
|
||||||
|
|
||||||
|
if(firstrun) {
|
||||||
|
LoRaWAN.displayMcuInit();
|
||||||
|
firstrun = false;
|
||||||
|
}
|
||||||
|
|
||||||
deviceState = DEVICE_STATE_INIT;
|
deviceState = DEVICE_STATE_INIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +129,14 @@ void productionLoop()
|
|||||||
}
|
}
|
||||||
case DEVICE_STATE_JOIN:
|
case DEVICE_STATE_JOIN:
|
||||||
{
|
{
|
||||||
|
LoRaWAN.displayJoining();
|
||||||
LoRaWAN.join();
|
LoRaWAN.join();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEVICE_STATE_SEND:
|
case DEVICE_STATE_SEND:
|
||||||
digitalWrite(LED_BLUE, HIGH);
|
digitalWrite(LED_BLUE, HIGH);
|
||||||
{
|
{
|
||||||
|
LoRaWAN.displaySending();
|
||||||
Serial.println("sending");
|
Serial.println("sending");
|
||||||
prepareTxFrame( appPort );
|
prepareTxFrame( appPort );
|
||||||
LoRaWAN.send();
|
LoRaWAN.send();
|
||||||
@ -145,6 +154,7 @@ void productionLoop()
|
|||||||
}
|
}
|
||||||
case DEVICE_STATE_SLEEP:
|
case DEVICE_STATE_SLEEP:
|
||||||
{
|
{
|
||||||
|
LoRaWAN.displayAck();
|
||||||
LoRaWAN.sleep(loraWanClass);
|
LoRaWAN.sleep(loraWanClass);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "production.h"
|
#include "production.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
|
||||||
// from config.cpp
|
// from config.cpp
|
||||||
extern config_t myConfig;
|
extern config_t myConfig;
|
||||||
|
|
||||||
bool productionMode = true;
|
bool productionMode = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED_BLUE, OUTPUT);
|
pinMode(LED_BLUE, OUTPUT);
|
||||||
@ -23,6 +24,8 @@ void setup() {
|
|||||||
|
|
||||||
if (productionMode) {
|
if (productionMode) {
|
||||||
productionSetup();
|
productionSetup();
|
||||||
|
} else {
|
||||||
|
configurationSetup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,5 +33,7 @@ void loop()
|
|||||||
{
|
{
|
||||||
if (productionMode) {
|
if (productionMode) {
|
||||||
productionLoop();
|
productionLoop();
|
||||||
|
} else {
|
||||||
|
configurationLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user