Project 22 - Weather Station

<< Click to Display Table of Contents >>

Navigation:  Projects >

Project 22 - Weather Station

This project creates an IOT weather station using an ESP8266 WiFi module attached to CleO. The CleO bridging libraries are used to allow the Arduino to communicate with ESP8266 over UART. Weather information is polled from The Arduino parses the HTTP responses from the server and constructs the GUI. The CleOWiFi module is connected to the CleO35 module.


Note: Ensure that CleO version 1.1.2 package and above is used for this project. If not upgraded, it will result in CleO firmware corruption and bootup failure.





This project uses the following component(s) -


CleOWiFi Click



Hardware Setup


The pictures below shows the CleOWiFi module connected to the CleO35 board.






The setup routine initializes the CleO35 display and the default GUI for the weather station. It then uses the CleO bridging library to reset and configure the EXP8266 WiFi module. Finally it connects to a local WiFi Access Point. Here is code snippet -


void setup()





/* Initialize CleO and build the default UI */


#if 0

 CleO.DisplayRotate(2, 0);




#if 1

/* Open GPIO handles for the RESET and ENABLE pins on the ESP8266 module */

 h_esp_enable = CleO.OpenGPIO(CLEO35_CN5_2,Bridge::gpio_dir::Output, Bridge::pad_pull_none);

 h_esp_reset = CleO.OpenGPIO(CLEO35_CN5_1, Bridge::gpio_dir::Output, Bridge::pad_pull_none);


/* Set ENABLE = 1 and toggle the RESET line */

 CleO.WriteGPIO(h_esp_enable, ((uint32_t)0x01 << CLEO35_CN5_2));

 CleO.WriteGPIO(h_esp_reset, (uint32_t)0);


 CleO.WriteGPIO(h_esp_reset, ((uint32_t)0x01 << CLEO35_CN5_1));



 Serial.println(F("==== UART Open ===="));

 h_esp_comm = (uint8_t)CleO.OpenUART(Bridge::interfaces::CleO35_CN5, Bridge::uart_baud::b115200, ESP_READ_TIMEOUT);


/* Load fixed icons that the UI always needs */

 char spf_buffer[32];

 strcpy_P(spf_buffer, ICON_Weather);

 im_t = CleO.LoadIcon(spf_buffer, ICON_THERMOMETER_50_PNG);

 strcpy_P(spf_buffer, ICON_Humidity);

 im_h = CleO.LoadIcon(spf_buffer, ICON_LOCATION_ON);

 strcpy_P(spf_buffer, ICON_Weather);

 im_w = CleO.LoadIcon(spf_buffer, ICON_WIND_PNG);

 strcpy_P(spf_buffer, ICON_Weather);

 im_r = CleO.LoadIcon(spf_buffer, ICON_UMBRELLA_PNG);


 strcpy_P(spf_buffer, ICON_REFSH);

 im_refresh = CleO.LoadIcon(spf_buffer, ICON_REFRESH);



The loop routine periodically polls the Open Weather Map server and parses it's response in real-time. The parsed data is cached in Arduino RAM, and the GUI is updated to reflect the latest information. URIs for current weather, today's forecast and the daily forecast are:


void loop()



/* Get the current weather at a given location */

if (poll.IsExpired(POLL_INTERVAL)) {


   /* Open a TCP socket at port 80 for HTTP */



   /* Send a HTTP GET request */



       /* Parse the response in real time as the Arduino SRAM is limited to 2KB */


         length = CleO.ReadAvailableUART(h_esp_comm, buffer);

         parsed = parse_json_response(buffer, length);



   /* Close socket */



  /* Set flag to update UI */

     update_ui = true;


/* Reset polling timer */




 /* Monitor touch events */

 if(control()) update_ui = true;


/* Build the UI if new data is available or a touch event is detected */

 if(update_ui) {





/* Free the icons loaded into CleO memory */





A typical JSON response returned by the server looks as below:



 "weather": [


     "id": 802,

     "main": "Clouds",

     "description": "scattered clouds",

     "icon": "03d"



 "base": "stations",

 "main": {

   "temp": 304.271,

   "pressure": 1019.9,

   "humidity": 82,

   "temp_min": 304.271,

   "temp_max": 304.271,

   "sea_level": 1020.59,

   "grnd_level": 1019.9


 "wind": {

   "speed": 6.76,

   "deg": 282.001


 "clouds": {

   "all": 32


 "dt": 1476338310,

 "id": 1880252,

 "name": "Singapore",

 "cod": 200







Project 22 - Weather