Guest User

Untitled

a guest
Jun 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <PubSubClient.h>
  3. #include <ESP8266httpUpdate.h>
  4. #include <ESP8266HTTPClient.h>
  5. #include <ArduinoJson.h>
  6. #include <FS.h>
  7. #include <ESPMetRED.h>
  8.  
  9.  
  10. const char* ssid = "xxx";
  11. const char* password = "yyy";
  12.  
  13. const char* MQTT_PUBLISH_TOPIC = "lumiblob/receive";
  14. const char* MQTT_SUBSCRIBE_TOPIC = "lumiblob/send";
  15. const char* CLIENT_ID = "ESPMetRED1";
  16. const char* WIFI_SSID = "xxx";
  17. const char* WIFI_PASSWORD = "yyyy";
  18. const char* MQTT_SERVER = "192.168.1.13";
  19. const char* MQTT_USER = "User_Name";
  20. const char* MQTT_PASSWORD = "Password";
  21.  
  22. ESPMetRED client;
  23.  
  24.  
  25. // RGB INTITIALISE
  26. #define REDPIN D1
  27. #define GREENPIN D2
  28. #define BLUEPIN D3
  29. // END RGB Initialise
  30.  
  31.  
  32.  
  33. //*********SETUP*****
  34. void setup() {
  35.  
  36. //JI Variables
  37. String JIESP="TBC";
  38. String JIMAC="TBC";
  39. int esp = 0;
  40. // end JI Variables
  41. // RGB LIGHT INITIALISE
  42. pinMode(REDPIN, OUTPUT);
  43. pinMode(GREENPIN, OUTPUT);
  44. pinMode(BLUEPIN, OUTPUT);
  45. // END RGB INITIALISE
  46.  
  47. // JI code to set which ESP8266
  48. String JIMAC2={WiFi.macAddress()};
  49. Serial.println("James JIMAC2 variable = ");
  50. Serial.println(JIMAC2);
  51.  
  52. if (JIMAC2=="A0:20:A6:13:E7:C3")
  53. {
  54. String JIESP="ESP1";
  55. int esp = 1;
  56. Serial.print("This is ESP A : ");
  57. Serial.println(JIESP);
  58. Serial.println(esp);
  59. }
  60.  
  61. Serial.print("This is ESP B : ");
  62. Serial.println(JIESP);
  63. Serial.print("This is ESP C : ");
  64. Serial.println(esp);
  65.  
  66. // End JI code to set which ESP8266
  67.  
  68. client.setCallback(callback);
  69. client.Publish("ESP8266 Number 1 connected");
  70.  
  71. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Begin code to publish to MQTT to say connected
  72. client.Publish("lumiblob/receive","ESPHEREA");
  73. client.Publish("lumiblob/receive","ESPHEREB");
  74. client.Publish("ESPHEREC");
  75. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++End code to publish MQTT to say connected
  76.  
  77. // end void setup
  78. }
  79.  
  80. // Perform your desired functions on payload received;
  81. void callback(String mqtt_payload)
  82. {
  83. // ENTER CODE HERE - Perform your desired functions on payload received;
  84. Serial.println('\n');
  85. Serial.println("ESP8266 received : "+ mqtt_payload);
  86. client.Publish("ESP8266 received " + mqtt_payload);
  87.  
  88. if (mqtt_payload="GO")
  89. {
  90. Serial.print("GO LOOP");
  91. analogWrite(REDPIN, 0);
  92. analogWrite(GREENPIN, 1000);
  93. analogWrite(BLUEPIN, 1000);
  94. delay(1000);
  95. analogWrite(REDPIN, 1000);
  96. analogWrite(GREENPIN, 0);
  97. analogWrite(BLUEPIN, 1000);
  98. delay(1000);
  99. analogWrite(REDPIN, 1000);
  100. analogWrite(GREENPIN, 1000);
  101. analogWrite(BLUEPIN, 0);
  102. delay(1000);
  103. analogWrite(REDPIN, 1000);
  104. analogWrite(BLUEPIN, 1000);
  105. analogWrite(GREENPIN, 1000);
  106. }
  107.  
  108. // END ENTER CODE - Perform your desired functions on payload received ABOVE HERE
  109. }
  110.  
  111. // ******* VOID LOOP START *************
  112. void loop() {
  113.  
  114. client.keepalive();
  115.  
  116. }
Add Comment
Please, Sign In to add comment