1 #include <ESP8266WiFi.h>
4 #include <PubSubClient.h>
5 const char* mqtt_server = "chrome";
6 const char* input = "inTopic" ;
7 const char* output = "outTopic" ;
9 WiFiClient espClient; // WiFi connection obj
10 PubSubClient client(espClient); // MQTT client obj
12 const byte ledPin = 2; // GPIO2 on LoLin Nodemcu
18 pinMode(ledPin, OUTPUT);
19 digitalWrite(ledPin, HIGH); // OnBoard LED is inverted
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.
30 if (!client.connected()) { // Keep MQTT connection on
35 client.publish(output, "Test Message");
39 void callback(char* topic, byte* payload, unsigned int length) {