Advertisement
pleasedontcode

Monitoring System rev_01

Apr 23rd, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Monitoring System
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-04-23 21:52:11
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* measure values of temperature and humidity every */
  21.     /* 10 seconds */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <DHT.h>
  26. #include <ESP8266WiFi.h>
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t dhtsensor_DHT11_DOUT_PIN_D4 = 4;
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. DHT dht(dhtsensor_DHT11_DOUT_PIN_D4, DHT11);
  37. WiFiClient client;
  38.  
  39. // System Requirements: Measure values of temperature and humidity every 10 seconds
  40.  
  41. void setup(void)
  42. {
  43.   // put your setup code here, to run once:
  44.   Serial.begin(9600);
  45.   delay(10);
  46.   dht.begin();
  47.   WiFi.begin(ssid, pass);
  48.   while (WiFi.status() != WL_CONNECTED) {
  49.     delay(500);
  50.   }
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   // put your main code here, to run repeatedly:
  56.   float h = dht.readHumidity();
  57.   float t = dht.readTemperature();
  58.  
  59.   if (isnan(h) || isnan(t)) {
  60.     return;
  61.   }
  62.  
  63.   if (client.connect(server, 80)) {
  64.     String postStr = apiKey + "&field1=" + String(t) + "&field2=" + String(h) + "\r\n\r\n";
  65.     client.print("POST /update HTTP/1.1\n");
  66.     client.print("Host: api.thingspeak.com\n");
  67.     client.print("Connection: close\n");
  68.     client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
  69.     client.print("Content-Type: application/x-www-form-urlencoded\n");
  70.     client.print("Content-Length: ");
  71.     client.print(postStr.length());
  72.     client.print("\n\n");
  73.     client.print(postStr);
  74.   }
  75.   client.stop();
  76.   delay(10000);
  77. }
  78.  
  79. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement