Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. #include
  2. #include
  3. #include
  4. #include
  5.  
  6. /************************* DHT22 Sensor *********************************/
  7. #define DHTTYPE DHT22
  8. #define DHTPIN 02
  9.  
  10. /************************* WiFi Access Point *********************************/
  11. const char* ssid = "TP-LINK_2.4GHz_B67322";
  12. const char* password = "5a0z3w8g4Q3m5x8";
  13.  
  14. /************************* MQTT Server *********************************/
  15. char* mqtt_server = "192.168.178.246";
  16. int mqtt_server_port = 1883;
  17. const char* mqtt_user = "w7m7HV";
  18. const char* mqtt_password = "w7m7HV";
  19. String message = "";
  20. String topicTemp = "";
  21. String topicHumid = "";
  22.  
  23. /************************* ESP8266 WiFiClient *********************************/
  24. WiFiClient wifiClient;
  25.  
  26. /************************* MQTT client *********************************/
  27. PubSubClient client(mqtt_server, mqtt_server_port, wifiClient );
  28.  
  29. /************************* DHT Sensor *********************************/
  30. DHT dht(DHTPIN, DHTTYPE, 11);
  31.  
  32.  
  33. float humidity, temp_f; // Values read from sensor
  34.  
  35. unsigned long previousMillis = 0; // will store last temp was read
  36. const long interval = 2000; // interval at which to read sensor
  37.  
  38. /*************not used yet, for subscription of messages ******************************/
  39. void callback(char* topic, byte* payload, unsigned int length) {
  40.  Serial.print("Message arrived [");
  41.  Serial.print(topic);
  42.  Serial.print("] ");
  43.  for (int i = 0; i " + String((int)temp_f) + "";
  44.  
  45. Serial.print(F("\nSending temperature value "));
  46. Serial.print(message);
  47. client.publish(topicTemp.c_str(), message.c_str());
  48.  
  49. message = "" + String((int)humidity) + "";
  50. Serial.print(F("\nSending humidity value "));
  51. Serial.print(message);
  52. client.publish(topicHumid.c_str(), message.c_str());
  53.  
  54. delay(1000);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement