configure and save hardware capabilities

This commit is contained in:
Ronald Schaten 2016-03-22 00:26:43 +01:00
parent 7a4bc046ab
commit 220ed8c10c

View File

@ -37,6 +37,9 @@ extern "C" {
char mqtt_server[40];
char mqtt_port[6] = "1883";
char mqtt_topic[34] = "OutTopic";
bool capability_dht = true;
bool capability_ldr = true;
bool capability_rgb = true;
// flag for saving data
bool shouldSaveConfig = false;
@ -239,6 +242,9 @@ void setup() {
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(mqtt_topic, json["mqtt_topic"]);
capability_dht = json["capability_dht"];
capability_ldr = json["capability_ldr"];
capability_rgb = json["capability_rgb"];
} else {
Serial.println("failed to load json config");
}
@ -253,6 +259,9 @@ void setup() {
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 5);
WiFiManagerParameter custom_mqtt_topic("topic", "mqtt topic", mqtt_topic, 32);
WiFiManagerParameter custom_capability_dht("dht", "capability dht", capability_dht ? "true" : "false", 5);
WiFiManagerParameter custom_capability_ldr("ldr", "capability ldr", capability_ldr ? "true" : "false", 5);
WiFiManagerParameter custom_capability_rgb("rgb", "capability rgb", capability_rgb ? "true" : "false", 5);
// local intialization
WiFiManager wifiManager;
@ -273,6 +282,9 @@ void setup() {
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_mqtt_topic);
wifiManager.addParameter(&custom_capability_dht);
wifiManager.addParameter(&custom_capability_ldr);
wifiManager.addParameter(&custom_capability_rgb);
// fetches ssid and pass and tries to connect
// if it does not connect it starts an access point
@ -291,6 +303,9 @@ void setup() {
strcpy(mqtt_server, custom_mqtt_server.getValue());
strcpy(mqtt_port, custom_mqtt_port.getValue());
strcpy(mqtt_topic, custom_mqtt_topic.getValue());
capability_dht = custom_capability_dht.getValue()[0] == 't';
capability_ldr = custom_capability_ldr.getValue()[0] == 't';
capability_rgb = custom_capability_rgb.getValue()[0] == 't';
// save the custom parameters to FS
if (shouldSaveConfig) {
@ -300,6 +315,9 @@ void setup() {
json["mqtt_server"] = mqtt_server;
json["mqtt_port"] = mqtt_port;
json["mqtt_topic"] = mqtt_topic;
json["capability_dht"] = capability_dht;
json["capability_ldr"] = capability_ldr;
json["capability_rgb"] = capability_rgb;
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {