Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : CMM2: V5.07.00b11: json support with full ESP-01 example code
Page 2 of 3 | |||||
Author | Message | ||||
elk1984 Senior Member Joined: 11/07/2020 Location: United KingdomPosts: 227 |
There's definitely some rumblings on this board in that direction CMM2 Expansion Board |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8815 |
It is worth checking the firmware version. The new ones I bought were on old V1.2.x firmware, latest is V1.7.4 and after upgrade the seem to work much better. Use AT+GMR to check the version I'll post full details on another thread |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3973 |
Looks like I am running an approximation of the latest: AT version:1.7.4.0(May 11 2020 19:13:04) SDK version:3.0.4(9532ceb) compile time:May 27 2020 10:12:17 Bin version(Wroom 02):1.7.4 I don't suppose you know if the ESP8266 is storing any state when it loses power, and how to clear that state ? It seems like once something goes bad, i.e. Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 Fatal exception (28): epc1=0x40001800, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00007ff0, depc=0x00000000 ... it stays bad even over a power-cycle and I'm not sure what eventually is causing it to clear. Regards, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6006 |
AT+RESTORE is the command to do a factory reset. I would try re-flashing your module anyway in case it have a bad byte or two stored. Jim VK7JH MMedit MMBasic Help |
||||
thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 3973 |
I would try re-flashing your module anyway in case it have a bad byte or two stored. Thanks for both Jim. I've ordered the necessary doodad and will experiment with "AT+RESTORE" the next time I encounter the issue. Best wishes, Tom Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 333 |
http://geoffg.net/Downloads/Maximite/CMM2_Beta.zip I've added a new edit font OPTION EDIT FONT VERY LARGE for use with high resolution modes and changed the horrible font 3 to a different one that is the same size This release also supports a json parsing function. I don't think my ESP-01 is working. The program in this thread doesn't run. It errors out at this line: if NOT OKwait(4000) then errorexit("AT+CWMODE_CUR=1") If I run the following, should I get OK back? I get nothing. open "COM2:115200,512" as #1 print #1,"AT"+chr$(13)+chr$(10) print input$(2,1) Edited 2021-08-07 15:48 by toml_12953 |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6006 |
If I run the following, should I get OK back? I get nothing. open "COM2:115200,512" as #1 print #1,"AT"+chr$(13)+chr$(10) print input$(2,1) You need a delay before reading the response. If you are adding the CRLF, add a ; to suppress the system newline. open "COM2:115200,512" as #1 print #1,"AT"+chr$(13)+chr$(10); pause 500 print input$(loc(#1),#1) Then try different baud rates. If you don't know what firmware your module is running, it is easier to reflash with something that you have the command reference for. Jim Edited 2021-08-07 17:21 by TassyJim VK7JH MMedit MMBasic Help |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 333 |
If I run the following, should I get OK back? I get nothing. open "COM2:115200,512" as #1 print #1,"AT"+chr$(13)+chr$(10) print input$(2,1) You need a delay before reading the response. If you are adding the CRLF, add a ; to suppress the system newline. open "COM2:115200,512" as #1 print #1,"AT"+chr$(13)+chr$(10); pause 500 print input$(loc(#1),#1) Then try different baud rates. If you don't know what firmware your module is running, it is easier to reflash with something that you have the command reference for. Jim Thanks for the response! It turned out to be a bad solder joint. I reflowed the solder and it works OK now. I won't be able to update the firmware version from 1.3.0 since it's soldered in but at least it works. I did download an AT reference and a full manual for it also so at least I know how it works. |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 435 |
The firmware I see in the download is B4. Is that correct? |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 333 |
Attached is some code that uses the openweathermap.org api which is called using an ESP-01 with the default "AT" firmware. You need to substitute your own wifi login details and your own openweathermap api username and key in lines 3, 4, and 14 to get it to work. This is code I previously published to work on the Micromite eXtreme that works without a single change on the CMM2 - Isn't compatibility wonderful You can see from the local report why I have so much time for coding I copied and pasted the code into my program. I have a free Openweather account and changed the three lines to access my WiFi network and Openweather account. When I run the program, I get this: Weather for Temperature is -273 Pressure is ain.temp ain.temp I've checked my user ID and API KEY a number of times and they're typed correctly. The network login procedure seems to be going through OK or the program would never reach the output lines. What might I be doing wrong? Edited 2021-08-08 20:20 by toml_12953 |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3096 |
To find out, you might need to see exactly what is being returned. The easiest way is to unplug your ESP8266 (oops) . . . Plug a spare ESP8266 into a USB ESP8266 module and plug into your PC, connect with puTTY or TeleTerm or your own fav and then manually enter what the CMM2 sends. Then you can get what the reply is, cut and paste it into a text file on the CMM2, and fiddle with the decoding code until you can see what's what (if it isn't evident when you look at it). Alternatively, you can cobble a splitter on CMM2 Rx and wire to a USB/ttl-serial module (with 0V also) and spy on the incoming text there. ~ Edited 2021-08-08 21:52 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8815 |
I'm not getting a response to CIPSTART today from api.openweathermap.org so can't help. Perhaps they have an issue or have changed something - anyone got anything working with openweathermap? |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3096 |
Using a PicoMite, which doesn't have JSON$, after "getinput(10000)", "longstring print m%()" gives this for Liverpool, Nova Scotia: {"coord":{"lon":-64.7155,"lat":44.0335},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":292.87,"feels_like":293.3,"temp_min":290.01,"temp_max":296.06,"pressure":1017,"humidity":92},"visibility":10000,"wind":{"speed":1.03,"deg":220},"clouds":{"all":100},"dt":1628429640,"sys":{"type":1,"id":549,"country":"CA","sunrise":1628414098,"sunset":1628465642},"timezone":-10800,"id":6057856,"name":"Liverpool","cod":200} [26] Print "Weather for "+json$(m%(),"name") PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3096 |
With an F4 with the same longstring print command, I get this (correct JSON breakout of values): {"coord":{"lon":-64.7155,"lat":44.0335},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":293.31,"feels_like":293.73,"temp_min":290.01,"temp_max":296.92,"pressure":1017,"humidity":90},"visibility":10000,"wind":{"speed":1.03,"deg":220},"clouds":{"all":100},"dt":1628430685,"sys":{"type":1,"id":549,"country":"CA","sunrise":1628414098,"sunset":1628465642},"timezone":-10800,"id":6057856,"name":"Liverpool","cod":200} Weather for Liverpool Temperature is 20.31 Pressure is 1017 overcast clouds PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3096 |
This version works on the PicoMite. A very limited, non-generic version of JSON$ is included, and 3 of the 4 calls to JSON$ are modified to fit the limitations of the JSON$ subroutine. ' weather.bas option explicit option default none Dim MYID$="MyID" Dim APIKEY$="MyKey" Dim report$="weather" dim b$= "GET /data/2.5/"+report$+"?id="+MYID$+"&APPID="+APIKEY$ Dim m%(8000) b$=b$+" HTTP/1.0"+Chr$(13)+Chr$(10)+Chr$(13)+Chr$(10) if instr(mm.device$,"Pico") then SetPin 21,uart0tx:SetPin 22,uart0rx open "com0:115200,8192" as #1 elseif instr(mm.device$,"F4") then open "com3:115200,8192" as #1 else print "COM PORT OPEN COMMAND NEEDED" end endif LongString clear m%() print #1,"AT+CWMODE_CUR=1"+chr$(13)+chr$(10); if NOT OKwait(4000) then errorexit("AT+CWMODE_CUR=1") print #1,"AT+CWJAP_CUR="+chr$(34)+"MyAP"+chr$(34)+","+chr$(34)+"MyPW"+chr$(34)+chr$(13)+chr$(10); if NOT OKwait(10000) then errorexit("AT+CWJAP_CUR=") print #1,"AT+CIPSTART="+chr$(34)+"TCP"+chr$(34)+","+chr$(34)+"api.openweathermap.org"+chr$(34)+",80"+chr$(13)+chr$(10); if NOT OKwait(10000) then errorexit("AT+CIPSTART=") print #1,"AT+CIPMODE=1"+chr$(13)+chr$(10); if NOT OKwait(4000) then errorexit("AT+CIPMODE=1") print #1,"AT+CIPSEND"+chr$(13)+chr$(10); if NOT OKwait(4000) then errorexit("AT+CIPSEND") print #1,b$; getinput(10000) 'longstring print m%() Print "Weather for "+json$(m%(),"name") if instr(mm.device$,"Pico") then Print "Temperature is ",val(json$(m%(),"temp"))-273 Print "Pressure is ",json$(m%(),"pressure") Print json$(m%(),"description") else Print "Temperature is ",val(json$(m%(),"main.temp"))-273 Print "Pressure is ",json$(m%(),"main.pressure") Print json$(m%(),"weather[0].description") endif print #1,"+++"; pause 1000 print #1,"AT+CIPMODE=0"+chr$(13)+chr$(10); if NOT OKwait(4000) then errorexit("AT+CIPMODE=0") print #1,"AT+CIPCLOSE"+chr$(13)+chr$(10); if NOT OKwait(4000) then errorexit("AT+CIPCLOSE") end function OKwait(timeout as integer) as integer OKwait=1 timer=0 do loop until input$(1,1)="O" or timer>=timeout do loop until input$(1,1)="K" or timer>=timeout if timer>=timeout then OKwait=0 end function sub errorexit(calling as string) print "AT call timeout from - ",calling print #1,"AT+CIPCLOSE"+chr$(13)+chr$(10) end end sub sub getinput(waitpause as integer) local a$ local j%,i%=-1 timer=0 do a$=input$(1,1) If a$<>"" Then LongString append m%(),a$ ' print a$; if a$="{" then if i%=-1 then i%=1 else i%=i%+1 endif endif if a$="}" then i%=i%-1 endif loop while timer<=waitpause and i%<>0 LongString trim m%(),LInStr(m%(),"{")-1 print "" end sub Function json$(ls%(),key$) local integer i,j,k,l,m local string a,b m=1 json$="" Do i=LInStr(ls%(),key$,m) ' Print key$,i If i Then a=LGetStr$(ls%(),i-1,1) b=LGetStr$(ls%(),i+Len(key$),1) ' Print "|";a;"|","|";b;"|"; If a=Chr$(34) And b=Chr$(34) Then ' found the key j=LInStr(ls%(),",",i+Len(key$)+2) If j>0 Then k=i+Len(key$)+2 a=LGetStr$(ls%(),k,j-k) ' Print a If Mid$(a,1,1)=Chr$(34) Then ' remove "s a=Mid$(a,2,Len(a)-2) EndIf If Instr(a,"}") Then: a=Mid$(a,1,Len(a)-1): EndIf json$=a Exit Do EndIf EndIf m=i+Len(key$) Else Exit Do ' key not found EndIf Loop End Function Weather for Liverpool Temperature is 21.39 Pressure is 1017 overcast clouds PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8815 |
Thanks for testing - good the code is working - don't know why I can't access the internet from my esp - must be a router issue UPDATE - did a AT+RESTORE on the ESP and now working with the posted code Edited 2021-08-09 01:29 by matherp |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 435 |
UPDATE - did a AT+RESTORE on the ESP and now working with the posted code I had the Same here. I did the AT+RESTORE and it worked right away. I got crap output but I did nothing but add my AP and PW and my username and code. What else do I need to do to get it localized and reporting right? |
||||
toml_12953 Guru Joined: 13/02/2015 Location: United StatesPosts: 333 |
UPDATE - did a AT+RESTORE on the ESP and now working with the posted code I had the Same here. I did the AT+RESTORE and it worked right away. I got crap output but I did nothing but add my AP and PW and my username and code. What else do I need to do to get it localized and reporting right? Adding your details to your account on the website should do it. |
||||
mclout999 Guru Joined: 05/07/2020 Location: United StatesPosts: 435 |
Thanks I will log in and see if I can find where to put the info. EDIT: In "Invoice info", I assume? I filled that in but I still get no info so far. Maybe it needs to propagate or something. I will try later. Edited 2021-08-09 14:30 by mclout999 |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8815 |
Set MYID$ to the code for where you want. Codes are downloaded from the weather site in a json file |
||||
Page 2 of 3 |
Print this page |