-->
Page 1 of 2

Not sure why this code isn't working.

PostPosted: Tue Sep 13, 2016 3:50 pm
by RyanC
I'm running the latest Basic version on a NodeMCU esp. For the moment, I am simply trying to retrieve latitude and longitude from a json and print it. If I push "run", the esp disconnects seemingly at once, returning no data, with the computer trying to load forever until i power cycle the esp. If I run it in debug, the code runs through about 4 times, returning the values correctly, then the esp disconnects. Can anyone offer me any insight?

Thanks
Code: Select alldelay 1000
Do
serialflush
cls
let query="api.open-notify.org/iss-now.json"
delay 1000
let ret = wget(query)
let latitude = json(ret,"latitude")
let longitude = json(ret,"longitude" )

print latitude & longitude
Loop until 0


Pardon the crudeness, very new to coding.

Re: Not sure why this code isn't working.

PostPosted: Wed Sep 14, 2016 3:55 am
by PhilTilson
The first thing I did was to remove all the 'let's which are know to cause problems in some places.

Next was to put spaces around the "=" sign in line 5 - they are necessary.

The program then froze at the 'cls' statement - I don't know why.

But when that was removed, everything ran sweetly - and indefinitely (well, as long as I was prepared to sit and watch it!)

Try this version:

Code: Select alldelay 1000

Do
  serialflush
  query$ = "api.open-notify.org/iss-now.json"
  delay 1000
  ret = wget(query$)
  latitude = json(ret,"latitude")
  longitude = json(ret,"longitude" )
  print latitude & "   " &  longitude
Loop until 0



Phil

Re: Not sure why this code isn't working.

PostPosted: Wed Sep 14, 2016 4:41 pm
by Mmiscool
The cls will not work because there is no wait command.

In order for the page in the browser to reload it must have a wait command.

Try using a timer to run the code periodically.

The timer branch must terminate with a wait.

Code: Select alltimer 1000, [get.data]
wait

[get.data]
  cls
  serialflush
  query$ = "api.open-notify.org/iss-now.json"
  ret = wget(query$)
  latitude = json(ret,"latitude")
  longitude = json(ret,"longitude" )
  print latitude & "   " &  longitude
wait


Re: Not sure why this code isn't working.

PostPosted: Thu Sep 15, 2016 4:00 am
by PhilTilson
Hmmm - I tried that code, but it still 'hung' at the CLS statement and I had to reboot.

Tried putting in a WAIT after the CLS (just to see!) and the program continually looped round the two statements, showing "connected... disconnected..." each loop. However, I was able to interrupt it (in DEBUG) this time.

Still not sure why this happens...

Phil