4
4
* \author
5
5
6
6
*/
7
- #include < SoftwareSerial.h>
7
+ // #include <SoftwareSerial.h>
8
8
#include < espduino.h>
9
9
#include < mqtt.h>
10
10
11
- SoftwareSerial debugPort (2 , 3 ); // RX, TX
12
- ESP esp (&Serial, &debugPort , 4 );
11
+ // SoftwareSerial debugPort(2, 3); // RX, TX
12
+ ESP esp (&Serial, &Serial , 4 );
13
13
MQTT mqtt (&esp);
14
14
boolean wifiConnected = false ;
15
15
@@ -21,7 +21,7 @@ void wifiCb(void* response)
21
21
if (res.getArgc () == 1 ) {
22
22
res.popArgs ((uint8_t *)&status, 4 );
23
23
if (status == STATION_GOT_IP) {
24
- debugPort .println (" WIFI CONNECTED " );
24
+ Serial .println (" Wifi connected " );
25
25
mqtt.connect (" yourserver.com" , 1883 , false );
26
26
wifiConnected = true ;
27
27
// or mqtt.connect("host", 1883); /*without security ssl*/
@@ -35,7 +35,7 @@ void wifiCb(void* response)
35
35
36
36
void mqttConnected (void * response)
37
37
{
38
- debugPort .println (" Connected " );
38
+ Serial .println (" MQTT connected " );
39
39
mqtt.subscribe (" /topic/0" ); // or mqtt.subscribe("topic"); /*with qos = 0*/
40
40
mqtt.subscribe (" /topic/1" );
41
41
mqtt.subscribe (" /topic/2" );
@@ -50,36 +50,35 @@ void mqttData(void* response)
50
50
{
51
51
RESPONSE res (response);
52
52
53
- debugPort .print (" Received: topic=" );
53
+ Serial .print (" Received: topic=" );
54
54
String topic = res.popString ();
55
- debugPort .println (topic);
55
+ Serial .println (topic);
56
56
57
- debugPort .print (" data=" );
57
+ Serial .print (" data=" );
58
58
String data = res.popString ();
59
- debugPort .println (data);
59
+ Serial .println (data);
60
60
61
61
}
62
62
void mqttPublished (void * response)
63
63
{
64
64
65
65
}
66
66
void setup () {
67
- Serial.begin (19200 );
68
- debugPort.begin (19200 );
67
+ Serial.begin (115200 );
69
68
esp.enable ();
70
69
delay (500 );
71
70
esp.reset ();
72
71
delay (500 );
73
72
while (!esp.ready ());
74
73
75
- debugPort .println (" ARDUINO: setup mqtt client" );
74
+ Serial .println (" ARDUINO: setup mqtt client" );
76
75
if (!mqtt.begin (" DVES_duino" , " admin" , " Isb_C4OGD4c3" , 120 , 1 )) {
77
- debugPort .println (" ARDUINO: fail to setup mqtt" );
76
+ Serial .println (" ARDUINO: fail to setup mqtt" );
78
77
while (1 );
79
78
}
80
79
81
80
82
- debugPort .println (" ARDUINO: setup mqtt lwt" );
81
+ Serial .println (" ARDUINO: setup mqtt lwt" );
83
82
mqtt.lwt (" /lwt" , " offline" , 0 , 0 ); // or mqtt.lwt("/lwt", "offline");
84
83
85
84
/* setup mqtt events */
@@ -89,18 +88,18 @@ void setup() {
89
88
mqtt.dataCb .attach (&mqttData);
90
89
91
90
/* setup wifi*/
92
- debugPort .println (" ARDUINO: setup wifi" );
91
+ Serial .println (" ARDUINO: setup wifi" );
93
92
esp.wifiCb .attach (&wifiCb);
94
93
95
94
esp.wifiConnect (" DVES_HOME" ," wifipassword" );
96
95
97
96
98
- debugPort .println (" ARDUINO: system started" );
97
+ Serial .println (" ARDUINO: system started" );
99
98
}
100
99
101
100
void loop () {
102
101
esp.process ();
103
102
if (wifiConnected) {
104
103
105
104
}
106
- }
105
+ }
0 commit comments