Skip to content

Commit 696e5d7

Browse files
authored
Merge pull request #1 from bloft/next
Next
2 parents 93b44d7 + 817dc37 commit 696e5d7

20 files changed

+1608
-704
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# EasyMqtt
22
Easy handling of Mqtt on esp8266
33

4-
Including a web interface to se current values, and avalible topic, and a rest api
4+
* Easy wifi configuration using web interface
5+
* Easy mqtt configuration using web interface
6+
* Easy configuration of mqtt endpoints
7+
* Web based UI to see current values
58

69
## Examble usage EasyMqtt
710
```C++
@@ -10,15 +13,15 @@ Including a web interface to se current values, and avalible topic, and a rest a
1013
EasyMqtt mqtt;
1114

1215
void setup() {
13-
// Setup wifi
14-
mqtt.wifi("ssid", "password");
15-
mqtt.mqtt("host", 1883, "user", "pass");
16+
mqtt.config().set("foo", "My Foo");
1617

17-
mqtt["foo"] << [](){ return String("bar"); };
18+
mqtt["foo"] << [&](){
19+
return String(mqtt.config().get("foo", "default"));
20+
};
1821
}
1922

2023
void loop() {
21-
mqtt.loop();
24+
mqtt.loop();
2225
}
2326

2427
```

ToDo.md

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,18 @@
22

33
## Improvements
44

5-
### Change MqttMap to include reference to mqttclient
6-
* Change loop, publish, ... to not need mqttclient
7-
85
### Add easyMqtt/$id/system/connected + will to indicate if device is online
96

7+
### OTA support
8+
Add support for OTA using ArduinoOTA
9+
1010
## Future
1111

1212
### Support writing to a topic with a subscriber
1313
Support both << and >> on the same topic with out read out own published values
1414

15-
### Add system info
16-
* easyMqtt/$id/system/uptime
17-
* easyMqtt/$id/system/mem
18-
* easyMqtt/$id/system/reset
19-
* easyMqtt/$id/system/debug
20-
* easyMqtt/$id/system/config
21-
22-
### Add better debugging
23-
* Add new EasyDebug class, extends Print (Print.h), and prints to easyMqtt/$id/system/debug if enabled
24-
* Add getDebugger on EasyMqtt that returns the EasyDebug instance
25-
26-
### Add support for filters
27-
* Don't send if value is the same as last.
28-
* Don't send if value is Nan
29-
30-
### Add support for float type (extend MqttMap)
15+
### Add support for float type (extend Entry)
16+
This will make it possible to generate graphs in UI and ease implementations
3117

3218
### Add publish configured endpoints, to support openhab2 auto configure
3319
something like
@@ -40,26 +26,3 @@ easyMqtt/$id/system/config
4026

4127
Read / Write / String / Number / ...
4228

43-
### Add config values
44-
Add config values that is persisted to flash memory
45-
46-
http://esp8266.github.io/Arduino/versions/2.0.0/doc/filesystem.html
47-
48-
```C++
49-
#include <EasyMqtt.h>
50-
51-
EasyMqtt mqtt;
52-
53-
setup() {
54-
// init config with name "test" with default value 123
55-
// The value can be changed using easyMqtt/$id/config/test
56-
// Is loaded from
57-
mqtt.config("timeout", 5000);
58-
}
59-
60-
loop() {
61-
mqtt.loop();
62-
mqtt.config("timeout"); // Read back config value
63-
}
64-
65-
```

examples/temperature/temperature.ino

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,12 @@ void setup() {
99
mqtt.wifi("ssid", "pass");
1010
mqtt.mqtt("server", 1883, "user", "password");
1111

12-
mqtt["temperature"] << []() {
13-
float value = dht.readTemperature();
14-
if(isnan(value)) {
15-
return String("");
16-
} else {
17-
return String(value);
18-
}
12+
mqtt["temperature"] << [&]() {
13+
return dht.readTemperature();
1914
};
2015

21-
mqtt["humidity"] << []() {
22-
float value = dht.readHumidity();
23-
if(isnan(value)) {
24-
return String("");
25-
} else {
26-
return String(value);
27-
}
16+
mqtt["humidity"] << [&]() {
17+
return dht.readHumidity();
2818
};
2919

3020
}

html/generateC

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
#!/usr/bin/php
22
<?php
33

4-
$html = file_get_contents("template.html");
5-
$pattern = "|<!-- split:(.*) -->|U";
4+
generateC("template.html", "../src/html.h");
5+
//generateC("test.html", "../src/html.h");
66

7-
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
7+
function generateC($input, $output) {
8+
$library = json_decode(file_get_contents("../library.json"), true);
89

9-
$split = preg_split($pattern, $html);
10+
$html = file_get_contents($input);
11+
$html = str_replace("{version}", $library['version'], $html);
12+
$html = str_replace("{easymqtt.url}", $library['repository']['url'], $html);
1013

11-
$tmp = array();
12-
foreach($matches as $key => $value) {
13-
if(!array_key_exists($value[1], $tmp)) {
14-
$tmp[$value[1]] = addslashes(trimContent($split[$key + 1]));
14+
$pattern = "|<!-- split:(.*) -->|U";
15+
16+
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
17+
18+
$split = preg_split($pattern, $html);
19+
20+
$tmp = array();
21+
foreach($matches as $key => $value) {
22+
if(!array_key_exists($value[1], $tmp)) {
23+
$tmp[$value[1]] = addslashes(trimContent($split[$key + 1]));
24+
}
25+
}
26+
27+
$fp = fopen($output, "w");
28+
fputs($fp, "#pragma once\n");
29+
fputs($fp, "\n");
30+
foreach($tmp as $header => $content) {
31+
$header = strtoupper($header);
32+
fputs ($fp, "const char HTML_${header}[] PROGMEM = \"$content\";\n");
1533
}
16-
}
34+
fclose ($fp);
35+
}
1736

1837
function trimContent($str) {
1938
$arr = explode("\n",$str);
@@ -23,15 +42,3 @@ function trimContent($str) {
2342
}
2443
return $output;
2544
}
26-
27-
$fp = fopen("../src/html.h", "w");
28-
fputs($fp, "#ifndef html_h\n");
29-
fputs($fp, "#define html_h\n");
30-
fputs($fp, "\n");
31-
foreach($tmp as $header => $content) {
32-
$header = strtoupper($header);
33-
fputs ($fp, "const char HTML_${header}[] PROGMEM = \"$content\";\n");
34-
}
35-
fputs($fp, "\n");
36-
fputs($fp, "#endif\n");
37-
fclose ($fp);

0 commit comments

Comments
 (0)