· 6 years ago · Oct 05, 2019, 12:40 AM
1/*
2Author: Rahul Shrivastava
3This programs send data to Thingspeak.com to a particular channel, here the data is collected by LM35
4Also, You donot need to hardcode SSID and PWD, it can be reconfigured using http://192.168.4.1,
5#connect to Autoconnect wifi hotspot, open URL "http://192.168.4.1"
6#and goto configure wifi and select available network, your device will connect to that network
7*/
8
9#include <Arduino.h>
10
11#include <ESP8266WiFi.h>
12#include <DNSServer.h>
13#include <WiFiManager.h>
14
15#include <ESP8266HTTPClient.h>
16
17float j=0;
18int sensor = A0;// analog input, anlog sensor is connected to this pin, LM35
19
20void setup() {
21
22
23 Serial.begin(115200);
24 Serial.flush();
25 WiFiManager wifiManager;
26 wifiManager.autoConnect("RS_Sensor_Node");
27 Serial.println("connected to Tonar_LM35_Sensor_Node:)");
28
29}
30
31void loop() {
32 float val = analogRead(sensor);
33 float vout = (val * 3300.0) / 1023;
34 float tempc = vout / 10; // Storing value in Degree Celsius
35 j = tempc;
36
37
38 HTTPClient http; //http is the object of class HTTPClient this class defines the method to create and send HTTP requests
39
40 Serial.print("Connected to HOTSPOT..\n");
41
42 String urlRS = "http://api.thingspeak.com/update?api_key=SCONMG0S3BGN3DPM&field1=";// api key of Tonar System lm35 channel(674722)
43 urlRS +=j;
44 http.begin(urlRS);
45
46 Serial.print("HTTP REQUEST SENT, Waiting for response\n");
47
48 // start connection and send HTTP header
49 int httpCode = http.GET();
50
51 // httpCode will be negative on error
52
53 if(httpCode > 0) {
54 // HTTP header has been send and Server response header has been handled
55 Serial.printf("Sensor data uploaded sucessfully");
56
57
58 }
59 else
60 {
61 Serial.printf("Failed to connect to server");
62 }
63 http.end();
64
65
66
67 delay(16000);
68}