Low Power Weather Device
Page last updated 11 Jul 2020, by .
0
replies
Team Members
- Yotam Ghebre
- Chris Hairston
- David Shoneye
Project Idea
- Quick environment weather data display optimized for low power.
- Stepper motors sweep to the desired number on paper display.
- Potentially reduce current draw to close to 1mA on average.
Hardware Setup
- An mbed LPC11u24 will be used as the master controller and is notable for its use of low power.
- The mbed LPC1768 will also be used to communicate with the "OpenWeatherMap" API by utilizing the "EthernetInterface" library, and will be powered off at all other times.
- Three stepper motors will be used to display current hourly: 1) Outdoor temperature, 2) Indoor humidity, 3) Indoor temperature.
- A temperature sensor will be used to access data regarding indoor temperature and humidity.
- Here is a short explanation of the device setup:
https://www.youtube.com/watch?v=7paQwth6QLs
Software Architecture
- Used the C++ programming language for the entire project.
- Depended on the “EthernetInterface.h” library for internet connectivity.
- Utilized the “OpenWeatherMap” API to access current hourly weather information including temperature, humidity, and current forecast description (i.e. scattered clouds) provided in json file format.
- The embed LPC11u24 library can be downloaded here:
- The embed LPC1768 library can be downloaded here:
Import programmbed1768FinalProject
This is implemented on 1768
- Here is a video demonstration of the device's hourly update: https://m.youtube.com/watch?v=TpjfYBt4gLE
- This code snippet below is for the mbed LPC1768 which is able to connect to the internet, request the current hourly weather data in a given city, and store it into a json.
int main()
{
pc.printf("\r\nThe Weather Report\n");
eth.init(); //Use DHCP
eth.connect();
pc.printf("IP Address is %s\r\n", eth.getIPAddress());
std::string mac;
mac = eth.getMACAddress();
pc.printf("MAC: %s\r\n", mac);
TCPSocketConnection sock;
sock.connect("api.openweathermap.org", 80);
char http_cmd[] = "GET /data/2.5/weather?q=Atlanta,US&APPID=a1c3afc7f18b7ef578cef48d5163cda6 HTTP/1.0\r\n\r\n";
if (!sock.is_connected()){
return -1;
}
sock.send_all(http_cmd, sizeof(http_cmd)-1);
char buffer[1000];
//int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
pc.printf("Received %d chars from server:\n%s\n", ret, buffer);
}
sock.close();
eth.disconnect();
float forecastHumidity=0;
// float temperature=-100;
float forcastTemp=0;
float forcastDescription = 0;
// float forcastPressure;
wait(10);
pc.printf("\r\nDHT Test program");
pc.printf("\r\n******************\r\n");
wait(1); // wait 1 second for device stable status
char cstr[resp.size() + 1];
while(1){
//GET forcast data
pc.printf("\nTrying to fetch page...\n");
//try getting the weather, 5 second timeout
// HTTPResult r = http.get("http://api.openweathermap.org/data/2.5/weather?q=Atlanta,US&APPID=a1c3afc7f18b7ef578cef48d5163cda6", resp, 5000);
// HTTPResult r = http.get("www.google.com", resp, 4096, 20000);
// ret = http.get("http://api.openweathermap.org/data/2.5/find?q=London",resp, 15000);
if(!ret){
std::string b2s(buffer, 1000);
int i = b2s.find("\r\n\r\n",0);
resp.assign(buffer+i+4);
pc.printf("responce=%s",resp);
strcpy(cstr, resp.c_str());
int len = strlen(cstr);
cstr[5] = '\n';
// json = NULL;
//char * result = NULL;
// asprintf(&result, "%s%s", json, "NULL");
// std::string sJson(json);
// pc.printf("parsing");
// const char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}";
//parse the previous string and fill the object demo
std::string newline= "\n";
resp.append(newline);
// std::string error = parse(v, cstr);
json = cstr;
struct weatherData{
std::string temp;
std::string desc;
std::string hum;
};
int beg, end;
weatherData weather;
//first find description
beg = json.find("description") + 14;
end = json.find("," , beg) - 1;
weather.desc = json.substr(beg,end-beg);
//next find temperature
beg = json.find("temp", end) + 6;
end = json.find("," , beg);
weather.temp = json.substr(beg,end-beg);;
//last find humidity
beg = json.find("humidity", end) + 10;
end = json.find(",", beg);
weather.hum = json.substr(beg,end-beg);
//
// pc.printf("humidity: %s", weather.hum);
// pc.printf("temp: %s", weather.temp);
// pc.printf("desc: %s", weather.desc);
// get time
std::time_t t = std::time(0);
std::time_t result = time(NULL);
// std::cout << std::asctime(std::localtime(&result))
printf("\n\nCurrent Time: %s \r\n",ctime(&result));
printf("Current Temperature: %s Kelvin \r\n",weather.temp);
printf("Humidity is %s \r\n",weather.hum);
printf("Weather Condition: %s \r\n", weather.desc);
}
}
}
Results and Future Work
- Currently reading a circuit current of 57.9 mA. Future goal is to fix current leakage to get expected current at approximately 1mA - 2mA.
- Collect and display more of the available weather info given on “OpenWeatherMap” including min temp, max temp, and wind speed, sunrise time, etc.
- Have a dedicated display for time.
Please log in to post comments.
