-->
Page 1 of 3

A little Weather Station Example

PostPosted: Sun Mar 06, 2016 11:50 am
by cicciocb
Hi all,
I published a video showing what can be done with the ESP8266 running Basic.
All the OpenWeather parsing and the control of the display is done in basic.
The display simply display the text sent by the ESP8266 via the serial port (I use the serial port 2 @ 115200).
The program parse the OpenweatherAPI for 2 towns and show the info on 2 scrolling lines.
As you can see you can do some nice things with the ESP8266 basic!

CiccioCB



For your info the program is the following :
Code: Select allmemclear()
let memo = ramfree()
serial2begin 115200

delay 100
serial2println "@SPD1=0"
serial2println "@SUP=$F2$CcWEATHER        "
delay 100
serial2println "@SPD2=0"
serial2println "@INF=$F3$C3DISPLAY         "
delay 2000
serial2println "Good Morning Everybody!"
delay 5000
serial2println "@SPD1=10"
serial2println "@SPD2=15"

memclear()
serial2println
let memo = ramfree()
serial2begin 115200
timer 40000 [get.weather]
let altern = 1
[start]
cls
Button "Exit" [Exit.prog]

[get.weather]
altern = 1 - altern
'if altern = 1 then goto [town2]
query = "api.openweathermap.org/data/2.5/weather?q=London,uk&lang=en&units=metric&appid=YOUR_APP_ID"
'let ret = readopenweather(query,0)
let ret = wget(query)
let desc = json(ret,"weather.description")
let temp = json(ret,"main.temp")
let press = json(ret,"main.pressure")
let humid = json(ret,"main.humidity")

let tim = json(ret,"dt")
let tim = unixtime(tim)
let name = json(ret,"sys.name")
'serialprint ret

query = "api.openweathermap.org/data/2.5/forecast/daily?q=London,uk&lang=en&units=metric&cnt=1&appid=YOUR_APP_ID"
let ret = readopenweather(query,1)
let temp_min = json(ret,"temp.min")
let temp_max = json(ret,"temp.max")
let tim = json(ret,"dt")
let tim = unixtime(tim)
serialprint tim

let mess = "$F1$C3" & name
let mess = mess & " $Cf"
let mess = mess & temp
let mess = mess & "$C3dg $Cf"
let mess = mess & press
let mess = mess & "$C3mB $CcHum $Cf"
let mess = mess & humid
let mess = mess & "$C3% $CcTmin $Cf"
let mess = mess & temp_min
let mess = mess & "$C3dg $CcTmax $Cf"
let mess = mess & temp_max
let mess = mess & "$C3dg $Cf"
let mess = mess & desc
let mess = mess & "   "
if instr(mess,"found") <> 0 then goto [town2]
serial2print "@SUP="
serial2println mess
serial2println name
serialprintln mess
serialprintln ramfree()
'wait

[town2]
query = "api.openweathermap.org/data/2.5/weather?q=Milan,it&lang=en&units=metric&appid=YOUR_APP_ID"
'let ret = readopenweather(query,0)
let ret = wget(query)
let desc = json(ret,"weather.description")
let temp = json(ret,"main.temp")
let press = json(ret,"main.pressure")
let humid = json(ret,"main.humidity")
let temp_min = json(ret,"main.temp_min")
let temp_max = json(ret,"main.temp_max")
let tim = json(ret,"dt")
let tim = unixtime(tim)
let name = json(ret,"sys.name")
serialprint ret

query = "api.openweathermap.org/data/2.5/forecast/daily?q=Milan,it&lang=en&units=metric&cnt=1&appid=YOUR_APP_ID"
let ret = readopenweather(query,1)
let temp_min = json(ret,"temp.min")
let temp_max = json(ret,"temp.max")
'serialprint ret
let tim = json(ret,"dt")
let tim = unixtime(tim)
serialprint tim

let mess = "$F1$C3" & name
let mess = mess & " $Cf"
let mess = mess & temp
let mess = mess & "$C3dg $Cf"
let mess = mess & press
let mess = mess & "$C3mB $CcHum $Cf"
let mess = mess & humid
let mess = mess & "$C3% $CcTmin $Cf"
let mess = mess & temp_min
let mess = mess & "$C3dg $CcTmax $Cf"
let mess = mess & temp_max
let mess = mess & "$C3dg $Cf"
let mess = mess & desc
let mess = mess & "   "
if instr(mess,"found") <> 0 then goto [town3]
serial2print "@INF="
serial2println mess
serial2println name
serialprintln mess
serialprintln ramfree()
[town3]
wait

[reset.memory]
memclear()
wait

[Exit.prog]


Re: A little Weather Station Example

PostPosted: Mon Mar 07, 2016 11:33 am
by viscomjim
Very Nice Job indeed!!! I must have missed when serial2begin and serial2println came up, but that is excellent. Can you tell me what pins are used for rxd and txd for serial2. Also how do you receive data on serial2? Would it be something like a$ = input2 ? This is a nice addition to be able to communicate with other MCUs using serial and still be able to use serial 1 for debug to a pc.

Where can we find details on this?

Thank you for all this new stuff. Really is getting better and better every time there is an update!!!!

Re: A little Weather Station Example

PostPosted: Mon Mar 07, 2016 2:42 pm
by cicciocb
Hi,
there are 3 commands linked to the serial port 2 :
serial2begin {baudrate}
serial2print var
serial2println var
these commands exist since some load, I think since the 1.83.
About the pins, unfortunately only the output pin is available as the RX is occupied for flash chip connection :-( .
Wrong choice done by the developers but this is outside our control :-).
You can find the details here, under the chapter Serial :
https://github.com/esp8266/Arduino/blob/master/doc/reference.md

For the pin, the TX2 is the GPIO2.

CiccioCB

Re: A little Weather Station Example

PostPosted: Mon Mar 07, 2016 4:27 pm
by viscomjim
Awww shucks about the no RX, but still very handy none the less. You made a very cool project!!!! Thank you for your efforts on this. Example code really helps a lot to explain proper command usage.