Post about your Basic project here

Moderator: Mmiscool

User avatar
By lew247
#46617 I'm trying to build a weather station using an outdoor unit transmitting via a 433Mhz transmitter to an indoor unit.
The indoor unit will have a 7" touchscreen and an ESP8266 to not only display the local weather, temp pressure etc from the outside unit but using the ESP8266 I want to be able to display things like the sea level pressure,sunrise, sunset and so on as well as weather details for another town.

Your example of a weather station is absolutely ideal for this I think.

I must point out I know nothing about ESPBasic other than the barest minimum.

What I'd like to do if you don't mind is modify your code and add a few things to it so it can do what I want, and also to send the information from my weather station TO Openweathermap.

I can understand a lot of your code, but as I'm new to ESPBasic I wonder if you'd mind helping by explaining a few things please/

serial2println = print out of serial port 2 I'm pretty sure I can change that to serialprintln to get it to print out of comn port 1, or would it be serial1println?

What I don't understand is the following snippets of code.
I wonder if you'd be so kind as to break them down and explain what each section/bit does please?
LIke: what does
ret
desc
tim
mess mean?
or let mess = mess & not sure what that means, basically all the code below

Code: Select alllet 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

et 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()


Also .... have you any idea how I would be able to format code to send my local data to openweathermap?
I do have an app id number.

Lewis
User avatar
By cicciocb
#46687 Hi,
to print on serial port 1 just type "serialprintln'.

For the rest, you can see in the example I gave that there is this line:
Code: Select allquery = "api.openweathermap.org/data/2.5/weather?q=London,uk&lang=en&units=metric&appid=YOUR_APP_ID"

This is a weather query for london,uk; replace inside this line with your town and put your app id number at the place of YOUR_APP_ID.
then the line
let ret = wget(query)
is simply where the query is done on apiweathermap. The result will be in the variable ret.
Then, because the result is given in json format, you need to use the function 'json()' to extract the information required.
let desc = json(ret,"weather.description") -> returns the description (wind calm, raining, ....)
let temp = json(ret,"main.temp") -> temperature
let tim = json(ret,"dt")
let tim = unixtime(tim) -> date / time of the weather information

Then, based on the way my external display works, I send all the information as a big string.
This is done in
let mess = mess & .....

There is also another query that is specific for forecast
Code: Select allquery = "api.openweathermap.org/data/2.5/forecast/daily?q=London,uk&lang=en&units=metric&cnt=1&appid=YOUR_APP_ID"


Here you need to use the function
ret = readopenweather(query,1) where the number define the day for the forecast
then the json is quite the same
let temp_min = json(ret,"temp.min")
let temp_max = json(ret,"temp.max")

If you have a specific town and specific information to display, please let me know and I'll show you how compose your query.

CiccioCB
User avatar
By lew247
#46715 Thank you so much, that has helped a lot
I'm still working on the hardware side of things, but once I get that finished I should be able to get the software side sorted relatively easy now.
Thank you
Lewis