The target of this project is to raise awareness about climate change.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
THINGHTTPCO2.inofirst esp826 sketch to take data from thingHTTPino - 1.82 kB - 03/21/2018 at 21:15 |
|
the first step of the project is to obtained the co2 level data. To do this, I choose to use the HTTPThing app from thingspeak, that allow to fetch data from every site and make it disponible trough an API.
The MCU that i choose to use is the well know ESP8266. Thanks to the ESP8266HttpClient library i can simply send a GET request to the thinghttp link and receive the daily data from www.co2.earth.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "MYWIFI";
const char* password = "*******";
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://api.thingspeak.com/apps/thinghttp/send_request?api_key=YAOX15VANMLMYH4S"); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
String todaydate = payload.substring(62,76);
String todayco2 = payload.substring(118,128);
Serial.print(todaydate);
Serial.print(" CO2 Level: "); //Print the response payload
Serial.println(todayco2);
httpCode == 0;
}
http.begin("http://api.thingspeak.com/apps/thinghttp/send_request?api_key=3TKGGW5Z5CHH7G0S"); //Specify request destination
httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString();
String agodate = payload.substring(36,50);
String agoco2 = payload.substring(92,99);//Get the request response payload
Serial.print(agodate);
Serial.print(" CO2 Level: "); //Print the response payload
Serial.println(agoco2); //Print the response payload
}
http.end(); //Close connection
}
delay(30000); //Send a request every 30 seconds
}
However co2.earth only maintain data histories about last year. So for the decade CO2 data i will use a text file downloaded from noaa server that contain world CO2 data from start of 20th century.
Create an account to leave a comment. Already have an account? Log In.
Become a member to follow this project and never miss any updates
I like when projects are aimed to help. Climate change is a very important problem that needs our active action. I research this topic for my college project and use a great variety of resources, including https://envrexperts.com/ to get more materials. These free essays on the environment contain interesting thoughts on how to reduce the level of global warming, pollution, and so on. People need to do something and it's great that there are such projects.