]> git.piffa.net Git - sketchbook_andrea/blobdiff - iot/mqtt_base/mqtt_base.ino
PWM correzione
[sketchbook_andrea] / iot / mqtt_base / mqtt_base.ino
diff --git a/iot/mqtt_base/mqtt_base.ino b/iot/mqtt_base/mqtt_base.ino
new file mode 100644 (file)
index 0000000..31babaa
--- /dev/null
@@ -0,0 +1,44 @@
+#include <ESP8266WiFi.h>
+void connection() ;
+
+#include <PubSubClient.h>
+const char* mqtt_server = "chrome";
+const char* input = "inTopic" ;
+const char* output = "outTopic" ;
+
+WiFiClient espClient; // WiFi connection obj
+PubSubClient client(espClient); // MQTT client obj
+
+const byte ledPin = 2; // GPIO2 on LoLin Nodemcu
+
+void setup() {
+  Serial.begin(115200);
+  delay(10);
+
+  pinMode(ledPin, OUTPUT);
+  digitalWrite(ledPin, HIGH); // OnBoard LED is inverted
+
+  connection();
+  client.setServer(mqtt_server, 1883);
+  client.setCallback(callback); //message callback function
+  // called when a message arrives for a subscription created by this client.
+  
+}
+
+void loop() {
+  
+if (!client.connected()) { // Keep MQTT connection on
+    reconnect();
+  }
+client.loop();
+
+client.publish(output, "Test Message");
+delay(500);
+}
+
+void callback(char* topic, byte* payload, unsigned int length) {
+
+
+}
+
+