· 6 years ago · Oct 04, 2019, 09:12 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 <ESP8266WiFiMulti.h>
14#include <WiFiManager.h>
15
16#include <ESP8266HTTPClient.h>
17
18float j=0;
19int sensor = A0;// analog input, anlog sensor is connected to this pin, LM35
20
21void setup() {
22
23
24 Serial.begin(115200);
25 Serial.flush();
26 WiFiManager wifiManager;
27 wifiManager.autoConnect("Tonar_LM35_Sensor_Node");
28 Serial.println("connected to Tonar_LM35_Sensor_Node:)");
29
30}
31
32void loop() {
33 float val = analogRead(sensor);
34 float vout = (val * 3300.0) / 1023;
35 float tempc = vout / 10; // Storing value in Degree Celsius
36 j = tempc;
37
38
39 HTTPClient http; //http is the object of class HTTPClient this class defines the method to create and send HTTP requests
40
41 Serial.print("Connected to HOTSPOT..\n");
42
43 String urlRS = "http://api.thingspeak.com/update?api_key=SCONMG0S3BGN3DPM&field1=";// api key of Tonar System lm35 channel(674722)
44 urlRS +=j;
45 http.begin(urlRS);
46
47 Serial.print("HTTP REQUEST SENT, Waiting for response\n");
48
49 // start connection and send HTTP header
50 int httpCode = http.GET();
51
52 // httpCode will be negative on error
53
54 if(httpCode > 0) {
55 // HTTP header has been send and Server response header has been handled
56 Serial.printf("Sensor data uploaded sucessfully");
57
58
59 }
60 else
61 {
62 Serial.printf("Failed to connect to server");
63 }
64 http.end();
65
66
67
68 delay(16000);
69}