initial
This commit is contained in:
24
ConfigGenerator/configGen.py
Normal file
24
ConfigGenerator/configGen.py
Normal file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from Cheetah.Template import Template
|
||||
|
||||
|
||||
|
||||
configItems = [
|
||||
{"label":"_", "key":"magic", "type":"I"},
|
||||
{"label":"Wifi SSID", "key":"wifiSsid", "type":"C", "length":32},
|
||||
{"label":"Wifi Key", "key":"wifiKey", "type":"C", "length":64},
|
||||
{"label":"MQTT Broker", "key":"mqttBroker", "type":"C", "length":64},
|
||||
{"label":"MQTT Username", "key":"mqttUser", "type":"C", "length":32},
|
||||
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32},
|
||||
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32},
|
||||
{"label":"MQTT Topic", "key":"mqttTopic", "type":"C", "length":64},
|
||||
{"label":"MQTT Port", "key":"mqttPort", "type":"I"},
|
||||
{"label":"Measure Period", "key":"measurePeriod", "type":"I"}
|
||||
]
|
||||
|
||||
|
||||
h_file = Template(file="configuration_h.tmpl", searchList=[{"configItems":configItems}])
|
||||
open('configuration.h','w').write(str(h_file))
|
||||
c_file = Template(file="configuration_c.tmpl", searchList=[{"configItems":configItems}])
|
||||
open('configuration.cpp','w').write(str(c_file))
|
65
ConfigGenerator/configuration_c.tmpl
Normal file
65
ConfigGenerator/configuration_c.tmpl
Normal file
@ -0,0 +1,65 @@
|
||||
#raw
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
|
||||
#include "configuration.h"
|
||||
#end raw
|
||||
|
||||
|
||||
tConfigBlock configBlock;
|
||||
const uint32_t MAGIC = 0xC0DE0001;
|
||||
extern ESP8266WebServer webServer;
|
||||
|
||||
void configServeIndex() {
|
||||
webServer.send(200, "text/html", ""
|
||||
"<!doctype html"
|
||||
"<html lang=\"en\">"
|
||||
" <head>"
|
||||
" <title>ESP8266 Thermometer Configuration Page</title>"
|
||||
" </head>"
|
||||
" <body>"
|
||||
" <h1>ESP8266 Configuration Page</h1>"
|
||||
" <form action=\"/config\" method=\"GET\">"
|
||||
" <table>"
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.label != "_"
|
||||
" <tr>"
|
||||
" <td>"
|
||||
" <label for\"$configItem.key\">$configItem.label</label>"
|
||||
" </td><td>"
|
||||
" <input type=\"text\" name=\"$configItem.key\" id=\"$configItem.key\"/>"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
#end if
|
||||
#end for
|
||||
" <tr>"
|
||||
" <td colspan=\"2\">"
|
||||
" <button type=\"submit\">Save</button>"
|
||||
" </td>"
|
||||
" </tr>"
|
||||
" </table>"
|
||||
" </form>"
|
||||
" </body>"
|
||||
"</html>"
|
||||
"");
|
||||
#ifdef DEBUG
|
||||
Serial.println("indexHtml request served");
|
||||
#endif
|
||||
}
|
||||
|
||||
void configServeGetConfiguration() {
|
||||
String arg;
|
||||
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.label != "_"
|
||||
arg = webServer.arg("$configItem.key");
|
||||
Serial.print("$configItem.key");
|
||||
Serial.println(arg);
|
||||
#end if
|
||||
#end for
|
||||
|
||||
webServer.send(200, "text/html", "configuration saved");
|
||||
}
|
||||
|
15
ConfigGenerator/configuration_h.tmpl
Normal file
15
ConfigGenerator/configuration_h.tmpl
Normal file
@ -0,0 +1,15 @@
|
||||
typedef struct {
|
||||
#for $configItem in $configItems
|
||||
#if $configItem.type == 'C'
|
||||
char ${configItem.key}[$configItem.length];
|
||||
#else if $configItem.type == 'I'
|
||||
uint32_t $configItem.key;
|
||||
#end if
|
||||
#end for
|
||||
} tConfigBlock;
|
||||
|
||||
extern const uint32_t MAGIC;
|
||||
extern tConfigBlock configBlock;
|
||||
|
||||
void configServeIndex();
|
||||
void configServeGetConfiguration();
|
Reference in New Issue
Block a user