|
1 | 1 | #include <Mokosh.hpp>
|
2 | 2 |
|
3 |
| -// global object for the framework |
4 |
| -Mokosh mokosh; |
| 3 | +// global object for the framework, disable using config file |
| 4 | +Mokosh mokosh("Mokosh", "1.0.0", false); |
5 | 5 |
|
6 |
| -void setup() { |
| 6 | +void setup() |
| 7 | +{ |
7 | 8 | srand(millis());
|
8 | 9 |
|
9 | 10 | // static configuration to be used: Wifi with yourssid and yourpassword password
|
10 | 11 | // mqtt broker at 192.168.1.10, port 1883
|
11 |
| - |
12 |
| - mokosh.setConfigFile(false); |
13 |
| - mokosh.config.set(mokosh.config.key_ssid, "yourssid"); |
14 |
| - mokosh.config.set(mokosh.config.key_wifi_password, "yourpassword"); |
15 |
| - mokosh.config.set(mokosh.config.key_broker, "192.168.1.10"); |
16 |
| - mokosh.config.set(mokosh.config.key_broker_port, 1883); |
| 12 | + mokosh.config->set(mokosh.config->key_ssid, "yourssid"); |
| 13 | + mokosh.config->set(mokosh.config->key_wifi_password, "yourpass"); |
| 14 | + mokosh.config->set(mokosh.config->key_broker, "192.168.1.10"); |
| 15 | + mokosh.config->set(mokosh.config->key_broker_port, 1883); |
17 | 16 |
|
18 | 17 | // device id will be Mokosh_ABCDE where ABCDE is a chip id
|
19 |
| - mokosh.begin("Mokosh"); |
| 18 | + mokosh.begin(); |
20 | 19 | }
|
21 | 20 |
|
22 | 21 | long lastMessage = 0;
|
23 | 22 |
|
24 |
| -void loop() { |
| 23 | +void loop() |
| 24 | +{ |
25 | 25 | // publish new random int message every 2000 ms
|
26 |
| - |
27 |
| - if (millis() - lastMessage > 2000) { |
| 26 | + |
| 27 | + if (millis() - lastMessage > 2000) |
| 28 | + { |
28 | 29 | // will publish to Mokosh_ABCDE/rand topic
|
29 |
| - mokosh.publish("rand", rand()); |
| 30 | + auto mqtt = mokosh.getMqttService(); |
| 31 | + mqtt->publish("rand", rand()); |
30 | 32 | lastMessage = millis();
|
31 | 33 | }
|
32 | 34 |
|
|
0 commit comments