]> git.piffa.net Git - sketchbook_andrea/blob - iot/mqtt_publish/mqtt_publish.ino
PWM correzione
[sketchbook_andrea] / iot / mqtt_publish / mqtt_publish.ino
1 #include <ESP8266WiFi.h>
2 void connection() ;
3
4 #include <PubSubClient.h>
5 const char* mqtt_server = "chrome";
6 const char* input = "inTopic" ;
7 const char* output = "outTopic" ;
8
9 WiFiClient espClient; // WiFi connection obj
10 PubSubClient client(espClient); // MQTT client obj
11
12 const byte ledPin = 2; // GPIO2 on LoLin Nodemcu
13
14 void setup() {
15   Serial.begin(115200);
16   delay(10);
17
18   pinMode(ledPin, OUTPUT);
19   digitalWrite(ledPin, HIGH); // OnBoard LED is inverted
20
21   connection();
22   client.setServer(mqtt_server, 1883);  
23 }
24
25 void loop() {
26   
27 if (!client.connected()) { // Keep MQTT connection on
28     reconnect();
29   }
30
31
32 char msg[50];
33  snprintf (msg, 75, "Test message @millis:  %ld", millis());
34 client.publish(output, msg);
35 delay(1000);
36
37 client.loop();
38 }
39