Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <PubSubClient.h>
- #include <ESP8266httpUpdate.h>
- #include <ESP8266HTTPClient.h>
- #include <ArduinoJson.h>
- #include <FS.h>
- #include <ESPMetRED.h>
- const char* ssid = "xxx";
- const char* password = "yyy";
- const char* MQTT_PUBLISH_TOPIC = "lumiblob/receive";
- const char* MQTT_SUBSCRIBE_TOPIC = "lumiblob/send";
- const char* CLIENT_ID = "ESPMetRED1";
- const char* WIFI_SSID = "xxx";
- const char* WIFI_PASSWORD = "yyyy";
- const char* MQTT_SERVER = "192.168.1.13";
- const char* MQTT_USER = "User_Name";
- const char* MQTT_PASSWORD = "Password";
- ESPMetRED client;
- // RGB INTITIALISE
- #define REDPIN D1
- #define GREENPIN D2
- #define BLUEPIN D3
- // END RGB Initialise
- //*********SETUP*****
- void setup() {
- //JI Variables
- String JIESP="TBC";
- String JIMAC="TBC";
- int esp = 0;
- // end JI Variables
- // RGB LIGHT INITIALISE
- pinMode(REDPIN, OUTPUT);
- pinMode(GREENPIN, OUTPUT);
- pinMode(BLUEPIN, OUTPUT);
- // END RGB INITIALISE
- // JI code to set which ESP8266
- String JIMAC2={WiFi.macAddress()};
- Serial.println("James JIMAC2 variable = ");
- Serial.println(JIMAC2);
- if (JIMAC2=="A0:20:A6:13:E7:C3")
- {
- String JIESP="ESP1";
- int esp = 1;
- Serial.print("This is ESP A : ");
- Serial.println(JIESP);
- Serial.println(esp);
- }
- Serial.print("This is ESP B : ");
- Serial.println(JIESP);
- Serial.print("This is ESP C : ");
- Serial.println(esp);
- // End JI code to set which ESP8266
- client.setCallback(callback);
- client.Publish("ESP8266 Number 1 connected");
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Begin code to publish to MQTT to say connected
- client.Publish("lumiblob/receive","ESPHEREA");
- client.Publish("lumiblob/receive","ESPHEREB");
- client.Publish("ESPHEREC");
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++End code to publish MQTT to say connected
- // end void setup
- }
- // Perform your desired functions on payload received;
- void callback(String mqtt_payload)
- {
- // ENTER CODE HERE - Perform your desired functions on payload received;
- Serial.println('\n');
- Serial.println("ESP8266 received : "+ mqtt_payload);
- client.Publish("ESP8266 received " + mqtt_payload);
- if (mqtt_payload="GO")
- {
- Serial.print("GO LOOP");
- analogWrite(REDPIN, 0);
- analogWrite(GREENPIN, 1000);
- analogWrite(BLUEPIN, 1000);
- delay(1000);
- analogWrite(REDPIN, 1000);
- analogWrite(GREENPIN, 0);
- analogWrite(BLUEPIN, 1000);
- delay(1000);
- analogWrite(REDPIN, 1000);
- analogWrite(GREENPIN, 1000);
- analogWrite(BLUEPIN, 0);
- delay(1000);
- analogWrite(REDPIN, 1000);
- analogWrite(BLUEPIN, 1000);
- analogWrite(GREENPIN, 1000);
- }
- // END ENTER CODE - Perform your desired functions on payload received ABOVE HERE
- }
- // ******* VOID LOOP START *************
- void loop() {
- client.keepalive();
- }
Add Comment
Please, Sign In to add comment