so far so good
This commit is contained in:
parent
04245e112c
commit
28b32656aa
@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
export PROJECTDIR=$PWD/..
|
||||
export PROJECTDIR=$PWD/../..
|
||||
|
||||
export PYTHONPATH=$PYTHONPATH:$PROJECTDIR
|
||||
|
||||
|
55
configurationMode.cpp
Normal file
55
configurationMode.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
s/*
|
||||
* configurationMode.cpp
|
||||
*
|
||||
* Created on: Aug 20, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
|
||||
#include "configurationMode.h"
|
||||
#include "../configuration.h"
|
||||
|
||||
|
||||
|
||||
|
||||
ESP8266WebServer webServer(80);
|
||||
|
||||
void configServeNotFound() {
|
||||
webServer.send(404, "text/plain", "page not found");
|
||||
#ifdef DEBUG
|
||||
Serial.println("page not found served");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setupConfigurationNetwork() {
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.softAP(CONFIG_SSID);
|
||||
#ifdef DEBUG
|
||||
Serial.println("AP started");
|
||||
#endif
|
||||
}
|
||||
|
||||
void setupConfigurationServer() {
|
||||
webServer.on("/", configServeIndex);
|
||||
webServer.on("/config", configServeGetConfiguration);
|
||||
webServer.onNotFound(configServeNotFound);
|
||||
webServer.begin();
|
||||
#ifdef DEBUG
|
||||
Serial.println("Webserver started");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loopConfiguration() {
|
||||
webServer.handleClient();
|
||||
}
|
||||
|
||||
|
||||
|
18
configurationMode.h
Normal file
18
configurationMode.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* configurationMode.h
|
||||
*
|
||||
* Created on: Aug 20, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef CONFIGURATIONMODE_H_
|
||||
#define CONFIGURATIONMODE_H_
|
||||
|
||||
|
||||
|
||||
void setupConfigurationNetwork();
|
||||
void setupConfigurationServer();
|
||||
void loopConfiguration();
|
||||
|
||||
|
||||
#endif /* CONFIGURATIONMODE_H_ */
|
17
defines.h-example
Normal file
17
defines.h-example
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* defines.h
|
||||
*
|
||||
* Created on: Aug 20, 2017
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef DEFINES_H_
|
||||
#define DEFINES_H_
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define CONFIG_SWITCH 0
|
||||
#define EEPROM_ADDR 0
|
||||
|
||||
|
||||
#endif /* DEFINES_H_ */
|
73
main.cpp
Normal file
73
main.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
#include "main.h"
|
||||
#include "defines.h"
|
||||
|
||||
// #define ESP8266
|
||||
|
||||
|
||||
#include <EEPROM.h>
|
||||
|
||||
#include "configuration.h"
|
||||
#include "productionMode.h"
|
||||
#include "configurationMode.h"
|
||||
|
||||
|
||||
|
||||
|
||||
bool configMode = false;
|
||||
|
||||
uint32_t startTime = 0;
|
||||
|
||||
|
||||
void mainSetup() {
|
||||
startTime = millis();
|
||||
#ifdef DEBUG
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting ...");
|
||||
#endif
|
||||
|
||||
pinMode(CONFIG_SWITCH, INPUT_PULLUP);
|
||||
|
||||
|
||||
EEPROM.begin(1024);
|
||||
EEPROM.get(EEPROM_ADDR, configBlock);
|
||||
|
||||
|
||||
Serial.print("Magic: ");
|
||||
Serial.println(configBlock.magic);
|
||||
Serial.print("ConfigSwitch: ");
|
||||
Serial.println(digitalRead(CONFIG_SWITCH));
|
||||
|
||||
|
||||
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
||||
|
||||
if (configMode) {
|
||||
#ifdef DEBUG
|
||||
Serial.println("Configuration mode");
|
||||
#endif
|
||||
setupConfigurationNetwork();
|
||||
setupConfigurationServer();
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
Serial.println("Production mode");
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
showConfiguration();
|
||||
#endif
|
||||
|
||||
setupProduction();
|
||||
setupConfigurationServer();
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("Started.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void mainLoop() {
|
||||
if (configMode) {
|
||||
loopConfiguration();
|
||||
} else {
|
||||
loopConfiguration();
|
||||
loopProduction();
|
||||
}
|
||||
}
|
24
main.h
Normal file
24
main.h
Normal file
@ -0,0 +1,24 @@
|
||||
// Only modify this file to include
|
||||
// - function definitions (prototypes)
|
||||
// - include files
|
||||
// - extern variable definitions
|
||||
// In the appropriate section
|
||||
|
||||
#ifndef _Main_H_
|
||||
#define _Main_H_
|
||||
#include "Arduino.h"
|
||||
//add your includes for the project RgbLed here
|
||||
|
||||
|
||||
//end of add your includes here
|
||||
|
||||
|
||||
//add your function definitions for the project RgbLed here
|
||||
|
||||
void mainSetup();
|
||||
void mainLoop();
|
||||
|
||||
|
||||
|
||||
//Do not add code below this line
|
||||
#endif /* _Main_H_ */
|
67
productionMode.cpp
Normal file
67
productionMode.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* productionMode.cpp
|
||||
*
|
||||
* Created on: Apr 05, 2019
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "../defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
#include "../configuration.h"
|
||||
|
||||
void setup_wifi() {
|
||||
delay(10);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
// We start by connecting to a WiFi network
|
||||
#ifdef DEBUG
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(configBlock.wifiSsid);
|
||||
#endif
|
||||
|
||||
WiFi.begin(configBlock.wifiSsid, configBlock.wifiKey);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(50);
|
||||
#ifdef DEBUG
|
||||
Serial.print(".");
|
||||
#endif
|
||||
}
|
||||
Serial.println("!");
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
#endif
|
||||
}
|
||||
|
||||
void __attribute__((weak)) setupApplication() {
|
||||
}
|
||||
|
||||
void __attribute__((weak)) loopApplication() {
|
||||
}
|
||||
|
||||
|
||||
void setupProduction() {
|
||||
setup_wifi();
|
||||
setupApplication();
|
||||
}
|
||||
|
||||
|
||||
void loopProduction() {
|
||||
loopApplication();
|
||||
}
|
||||
|
||||
|
19
productionMode.h
Normal file
19
productionMode.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* productionMode.h
|
||||
*
|
||||
* Created on: Apr 5 2019
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef PRODUCTIONMODE_H_
|
||||
#define PRODUCTIONMODE_H_
|
||||
|
||||
|
||||
|
||||
void setupProduction();
|
||||
void loopProduction();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* PRODUCTIONMODE_H_ */
|
Loading…
x
Reference in New Issue
Block a user