]> git.piffa.net Git - sketchbook_andrea/blob - iot/mqtt_base/mqtt_base.ino
PWM correzione
[sketchbook_andrea] / iot / mqtt_base / mqtt_base.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   client.setCallback(callback); //message callback function
24   // called when a message arrives for a subscription created by this client.
25   
26 }
27
28 void loop() {
29   
30 if (!client.connected()) { // Keep MQTT connection on
31     reconnect();
32   }
33 client.loop();
34
35 client.publish(output, "Test Message");
36 delay(500);
37 }
38
39 void callback(char* topic, byte* payload, unsigned int length) {
40
41
42 }
43
44