Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include
- #include
- #include
- #include
- /************************* DHT22 Sensor *********************************/
- #define DHTTYPE DHT22
- #define DHTPIN 02
- /************************* WiFi Access Point *********************************/
- const char* ssid = "TP-LINK_2.4GHz_B67322";
- const char* password = "5a0z3w8g4Q3m5x8";
- /************************* MQTT Server *********************************/
- char* mqtt_server = "192.168.178.246";
- int mqtt_server_port = 1883;
- const char* mqtt_user = "w7m7HV";
- const char* mqtt_password = "w7m7HV";
- String message = "";
- String topicTemp = "";
- String topicHumid = "";
- /************************* ESP8266 WiFiClient *********************************/
- WiFiClient wifiClient;
- /************************* MQTT client *********************************/
- PubSubClient client(mqtt_server, mqtt_server_port, wifiClient );
- /************************* DHT Sensor *********************************/
- DHT dht(DHTPIN, DHTTYPE, 11);
- float humidity, temp_f; // Values read from sensor
- unsigned long previousMillis = 0; // will store last temp was read
- const long interval = 2000; // interval at which to read sensor
- /*************not used yet, for subscription of messages ******************************/
- void callback(char* topic, byte* payload, unsigned int length) {
- Serial.print("Message arrived [");
- Serial.print(topic);
- Serial.print("] ");
- for (int i = 0; i " + String((int)temp_f) + "";
- Serial.print(F("\nSending temperature value "));
- Serial.print(message);
- client.publish(topicTemp.c_str(), message.c_str());
- message = "" + String((int)humidity) + "";
- Serial.print(F("\nSending humidity value "));
- Serial.print(message);
- client.publish(topicHumid.c_str(), message.c_str());
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement