My working ESP8266 weather forecast example..

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
MJU
Posts: 502
Joined: Wed Nov 07, 2007 6:51 pm
Location: Antwerp Belgium
Has thanked: 121 times
Been thanked: 108 times
Contact:

My working ESP8266 weather forecast example..

Post by MJU »

I've made a weather forecast example with the Flowcode ESP8266 (ESP) Wifi component. :D

This shows the forecast for the next 10 days on a 4*20 LCD display for my hometown.
Before I write a thing about the actual file, I need to point to certain sources on which I found the information to get this file working or things you should do before using the example.

1- The ESP8266 example files in the Matrix Wiki.
2 - A few posts on the Flowcode forum that I used.
Be sure to read this post: http://www.matrixtsl.com/mmforums/viewt ... 266#p74063 before using the component. Here you can find a bit about how different Firmware versions on the ESP lead to different reply's from the module.
3- Check if you are using the latest ESP8266 macro for your version of Flowcode. (from the Matrix website)
4- Check the ESP8266 macro settings! Be sure you get the ESP response settings right I used a logic analyser to view my Firmware responses). Be sure to set the baud rate the same for the module and the settings in Flowcode. If you have a hardware reset, set this property in the ESP properties of the macro. I used the Software reset.
5- Be sure to view this tutorial by Kevin Darrah, it is incredibly useful if you want to grab data from the internet: http://www.codingcraze.com/cheap-and-ea ... etupintro/
6- Be sure to get the module working before you try using the modules with Flowcode. There are a lot of power problems that make it difficult to start with the ESP8266 modules.
Also, make sure you have a good level converter (if you use a 5V microcontroller). The ESP uses 3.3V and the levels must meet the values described in the datasheet.

My example:
I used the ESP01 version of the board. These are very very cheap on Ebay. :-)
As a level converter I use a breakout board bought on Ebay (or something like that). This board has a level shifter AND a 5->3.3V voltage converter. It seems to have power enough to make the ESP8266 work fine.
I have a PIC 18F4550 on a EB006 Matrix Multiprogrammer with a 4*20 LCD display (PortB), the ESP8266 is connected on the RX-TX on port C (check with the controller you use), and I have a LED board on port D.
This LED board is only used for checking the timing of the PIC. (the famous Flasher that goes on for half a second and the off for half a second).

I use YQL (Yahoo query language), and make it generate the weather forecast for a specific place and with metric units for temperature, windspeed and so on.
The result of this query is send via Thingspeak, and this information is grabbed by the ESP8266.
Watch the Kevin Darrah tutorial...!!

The Flowcode program I've made is based on the TCP Client example on the Matrix Wiki page.
It contains 4 macro's.
Main:
This first makes the Flasher macro run (this only flashes the LED on/off)
Starts/initializes the other components (LCD/ESP8266).
Then it tries to join the Wifi access point at my home (be sure to change it to your SSID and password).
If it works it show "OK", otherwise "Fail".
A bit further it tries to connect with Thingspeak on port 80.
Again it tells if it works or failed.
It there is a connection with Thingspeak it sends the query that I use to grab the information I want (Kevin Darrah tutorial).

I use:
"GET https://api.thingspeak.com/apps/thinght ... RU\r\n\r\n" . Be sure to add the \r\n\r\n at the end of the GET command that Thingspeak generates.
I wait a few 100msec because I found out with my logic analyzer that it takes >200msec to receive the requested data.
Now I wait for incoming data and I will process them immediately. This maybe isn't the best tactic, but for now it works.
After I receive a byte, I use an interrupt to go to the macro "Filter".
All this does is try to filter the data I want to display into string variables.
The way I do this is a bit brute force because I don't know right now how to accomplish this in a better (faster) way. (more about this macro later).

The strings I receive from Yahoo (via Thingspeak) contains a lot of data that I want to use and a lot I want to get rid of. It sends back more than 1000bytes so I process them as soon as I can.

If the filter macro has put all the data I need into string variables, I look at the temperature strings to detect of it starts with a "-".
If the temperature is negative nothings happens, but if one of the temperatures is positive, the bytes are send one place to the right, and the first digit is replaced by a space. This makes that there aren't strange signs in the third place of the string.

After this is done, the "Display" macro is called.
All this does is show the data "Day / Date" "Hi and Lo temp" and the "forecast text" for each and every of the 10 days to follow.
This file isn't perfect.

The processing of the incoming data is done in a short while via a macro call..
During the time between two received bytes it has to finish.
In this case the filtering is too slow, so from day 8 on I get a lot of rubbish on the display.
This doesn't matter for me, 7 days forecast is good enough for me.
I hope to get feedback on this one. If someone has a better tactic to filter the data, please let me know!

The data I receive is a lot of blabla that I can't use.
I only need data after a string that contains: "Date", "Day", "High" "Low" and "Text".
To extract these I use filters that searches for some specific strings.
Example: the unique thing to filter the date is te":
I search for every t (ASCII 116), and every time this is found, there is a variable increased, if after that it finds a e (ASCII 101), it continues the filtering in search of te": .
Then it looks for " (ASCII 034), and finally : (ASCII 58). If one of the bytes aren't what I expected, it starts from the beginning.
If these are all found next to each other I'm sure that after the next quotes the data for the date is found". So now I wait until a " is found (ASCII 34) and from now on I put the received data in a string.
If another " is found, it stops.
Now the macro searches for the next starting point (the day which is found after ASCII: 097 121 034 058)
After the macro has found all of the strings it needs, he starts over and searches for the next group of data.
In this way I receive "Date1" "Day1", High1" "Low1", "Text1", Date2" "Day2", High2" "Low2", "Text2", "Day3" .. and so on.
These strings can be handled afterwards.

I would really receive comment's on the file, how I can improve it.
Especially the filtering is something that can be done better. If I could use a circular buffer that could store all bytes (up to >3000bytes), I wouldn't have to do the filtering in real time.

All comments are welcome but I can't offer support.
Oh yes, and please share your files with the rest of the world! :)
Attachments
ESP8266_weather forecast ENG.fcfx
(103.38 KiB) Downloaded 502 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: My working ESP8266 weather forecast example..

Post by Benj »

Very cool, thanks for sharing.

I will certainly be having a good look through this project as I want to do something similar with an ESP8266 and some sensors.

Post Reply