Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:53 29 Nov 2024 Privacy Policy
Jump to

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 : PicoMiteWeb alphas a21+  NTP rework

     Page 1 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 10:52am 05 Mar 2023
Copy link to clipboard 
Print this post

PicoMiteWeb V5.07.07a21

PicoMiteWebV5.07.07a21.zip

Fixes bug in TEMPR command and function at standard CPU speeds

I've re-engineered WEB NTP as many of you seem to be having problems. You can now also select the ntp server

WEB NTP [timeoffset [, ntpserver$]]


e.g.

web ntp 0,"uk.pool.ntp.org"


Note, if you want to specify the ntp server you must specify a timeoffset (standard limitation of MMBasic). The server can be specified either as a text or numerical IP address e.g. "uk.pool.ntp.org" or "217.114.59.3"

This version also has a significant internal change to memory utilisation and now has 84Kb available for programs. It is also about 20% faster than before.

Usual flash/option warning

WEB MQTT will now allow 8883 addresses and use TLS. HOWEVER, it does not support SSL over TLS which commercial MQTT servers may require. I don't think this will ever be possible given the memory limitations of the RP2040.

Please report any issues
Edited 2023-03-05 20:53 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6103
Posted: 11:14am 05 Mar 2023
Copy link to clipboard 
Print this post

Thanks for the NTP work.
I have only had a missed read once in a few hundred requests but I am pleased that I will be able to use my own GPS derived NTP server.

Jim
VK7JH
MMedit   MMBasic Help
 
Michal
Senior Member

Joined: 02/02/2022
Location: Poland
Posts: 123
Posted: 05:28pm 05 Mar 2023
Copy link to clipboard 
Print this post

Hi @matherp

Trying to receive a message from PicoMiteWebV5.07.07a21 on a test MTQQ Server/Client compiled in Delphi11-Win32:
MQTTSC
(may be needed libssl-1_1.dll, libcrypto-1_1.dll. Login: admin/password)
And on the Pico client I get an error and on the server a quick instant disconnection after logging in.
What is wrong.

Michal
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 05:32pm 05 Mar 2023
Copy link to clipboard 
Print this post

  Quote  it does not support SSL
 
Michal
Senior Member

Joined: 02/02/2022
Location: Poland
Posts: 123
Posted: 05:50pm 05 Mar 2023
Copy link to clipboard 
Print this post

  matherp said  
  Quote  it does not support SSL

This server seems to work in both SSL and non-SSL modes.

Michal
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 06:00pm 05 Mar 2023
Copy link to clipboard 
Print this post

I just use the Mosquitto server for test. Easy to install on windows and works perfectly. There are videos on youtube explaining how to get it up and running
 
Michal
Senior Member

Joined: 02/02/2022
Location: Poland
Posts: 123
Posted: 06:08pm 05 Mar 2023
Copy link to clipboard 
Print this post

Oops.
Sorry.

MQTTSC1
I added the missing *.pem files.

Michal
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 06:12pm 05 Mar 2023
Copy link to clipboard 
Print this post

Sorry, but life is too short to try and diagnose every MQTT broker variant. It is down to you to diagnose.
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 08:28pm 05 Mar 2023
Copy link to clipboard 
Print this post


Peter, thank you!
Now my own NTP server works :-)

PicoMiteWeb MMBasic Version 5.07.07a21
Copyright 2011-2023 Geoff Graham
Copyright 2016-2023 Peter Mather

Connecting to WiFi...
Connected 192.168.1.133
Starting server at 192.168.1.133 on port 80
> print time$
00:00:11
> web ntp 1,"192.168.1.1"
ntp address 192.168.1.1
got ntp response: 05/03/2023 21:26:31
> option web ntp 1,"192.168.1.1"
Error : Invalid Option
> option ntp 1,"192.168.1.1"
Error : Invalid Option
>

But how can I have the time automatically queried directly at startup?

Matthias
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 08:36pm 05 Mar 2023
Copy link to clipboard 
Print this post

sorry - there was nonsense here
Edited 2023-03-06 06:38 by homa
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 10:31pm 05 Mar 2023
Copy link to clipboard 
Print this post

  Quote  But how can I have the time automatically queried directly at startup?


sub mm.startup
web ntp 1,"192.168.1.1"
end sub
 
JanVolk
Senior Member

Joined: 28/01/2023
Location: Netherlands
Posts: 145
Posted: 10:34pm 05 Mar 2023
Copy link to clipboard 
Print this post

Peter,

It now all works without problems with the DS18B20 sensor and has worked for half a day without errors with PicoMiteWeb Version 5.07.07a21 and PicoMite Version 5.07.07b25.
Also nice that the Web version and the other versions at Edit now show a red message "LINE IS TO LONG" which I have not noticed before what an improvement.
With the Web version, after reset, PicoMiteWeb MMBasic Version 5.07.07a21.
And after Option list comes the Web version PicoMite MMBasic Version 5.07.07a21.

Jan
 
RonnS
Senior Member

Joined: 16/07/2015
Location: Germany
Posts: 120
Posted: 10:57pm 05 Mar 2023
Copy link to clipboard 
Print this post

Hello Peter M, first of all, thank you for your diligent work
So far everything has worked for me and I haven't had any problems.
for the future I ask: will it be possible to play an internet radio stream or a video stream, for example:
eg PlayStream" internet address" as MP3/Stream or somthing else ?
or a camera stream? just as easy as your "jokebox"
the ESP32 can do that!


Thank you and I really appreciate your work
Ron

example for an Radio stream :

http://www.beatlesradio.com:8000/stream
or
http://81.17.57.158:24929/stream
Edited 2023-03-06 09:20 by RonnS
 
aFox
Regular Member

Joined: 28/02/2023
Location: Germany
Posts: 76
Posted: 05:28pm 06 Mar 2023
Copy link to clipboard 
Print this post

PicoMiteWeb is pretty promising.
Perhaps I may add another suggestion here.
RFO-Basic for Android used for data transfer via WiFi/Ethernet "sockets".

See https://www.tapatalk.com/groups/rfobasic/android-connection-to-pc-by-browser-t5787.html#p42289 for an example Http server.

Manual RFO-Basic 1.91:
https://gitlab.com/OliBasic/Main/-/blob/master/OliBasicXXIV/Documentation/RFO-Basic%20Manual%201.91%20De_Re_BASIC!.pdf

Manual Appendix OliBasic 3.00+:
https://www.tapatalk.com/groups/rfobasic/download/file.php?id=5677

Fork of RFO-Basic 1.91 with a lot of enhancements, OliBasic 3.00+:
https://www.tapatalk.com/groups/rfobasic/olibasic-3-0-preview-t6292-s40.html#p48256

See the Socket, Http, Byte and Html commands.

Maybe you get ideas, hints or something else.

An option is collecting the data (maybe via device hotspot) of some Picos and its processing by a "Basic" interpreter on Android also.

Gregor
Edited 2023-03-07 03:30 by aFox
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 01:26am 07 Mar 2023
Copy link to clipboard 
Print this post

Hi all,
My Pico-W is still crashing but I can't identify potential caus(es) yet (I have a test running).

It crashes and prints to the console:

"*** PANIC ***

Out of Heap memory"

BUT I have uncovered one quirk.
My code (see below) checks the Pico-W's TIME$ in a DO-LOOP and at "00" seconds every 5 minutes it calls up NTP (this is a test, in real life it will be much less frequent).

BUT it is called up twice in about one second.

I suspect that the Pico-W's time is running a fraction slow and is seeing the same 15 minute trigger twice.

The capture below illustrates it.

My fix is to insert a 250ms delay before the NTP call so the Pico TIME$ has progressed to the next second and fails the "00" test.
(the code below is AFTER the fix was inserted - it now appears to be working well. I am still waiting for the next *** PANIC *** attack due to causes unknown.)

Any comments or suggestion?

Cheers,

Andrew



Console capture (with A_G comments after <<):

RUN
Pico-W_OWeather v2 for TBS.BAS Started 01-04-2000 at 11:22:26 (local - before NTP)
02-04-2000 00:00:00
01-10-2000 00:00:00
ntp address 103.126.53.123
got ntp response: 07/03/2023 11:22:26
07-03-2023  11:22:26
.
.
.
11:25:00 Flag ON                        <<Flag is set at 11:25:00 (Pico-W TIME$), calls for NTP
02-04-2000 00:00:00
01-10-2000 00:00:00
ntp address 162.159.200.123
got ntp response: 07/03/2023 11:24:59   <<NTP responds and resets Pico-W TIME$ to 11:24:59
07-03-2023  11:24:59
11:24:59 Flag OFF                       <<Pico-W's TIME$ passes 11:25:00 so calls for another NTP (about 1 second after the last one)
11:25:00 Flag ON
02-04-2000 00:00:00
01-10-2000 00:00:00
ntp address 162.159.200.123
got ntp response: 07/03/2023 11:25:00   <<NTP responds and resets Pico-W's TIME$ to 11:25:00
11:25:01 Flag OFF
.
.
.




'Pico-W_OWeather v1a for TBS.BAS
 OPTION EXPLICIT
 OPTION DEFAULT Integer
 
 dim String Version = "Pico-W_OWeather v2 for TBS.BAS"
 
 'OPTION WIFI MySSID, MyPassword   'This OPTION is held in flash until changed or re-flashed
 'OPTION WIFI "***********", "***********"
 
 Const True = 1
 Const False = 0
 
 'Flags:
 dim Integer Fl.NewPeriod = False
 
 DATE$ = "01-04-2000"
 ' Tassyjim - March 2023
 DIM Integer Tzone = 10  'Jim's code adds DST when appropriate AEST (11 for DST)
 
 Print Version; " Started ";DATE$;" at "; Time$; " (local - before NTP)"
 Get_NTP   'Get initial values from NTP
 
 SETTICK 10000, NewTime, 1
 
 'MAIN LOOP'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 do
   'Watchdog 60000   'ZZZ leave out until code is in use
   if mid$(TIME$,7,2)="00" and VAL(mid$(TIME$,4,2)) Mod 5=0 and not Fl.NewPeriod Then 'A new 5 minute
     Fl.NewPeriod = True
     Timer = 0
     print
     print time$; " Flag ON"
do: Loop while timer < 250
     Get_NTP
   End If  'A new 5 min
   
   if mid$(TIME$,7,2)<> "00" and Fl.NewPeriod Then '1 second after start of the new minute
     print time$; " Flag OFF"
     Fl.NewPeriod = False
   End IF
 Loop
 'main loop'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
sub NewTime
 print ".";   'just a heartbeat
End Sub
 
Sub Get_NTP
 local string TempDate, TempTime
 local Integer Tmp
 ' NTP Timeout loop by TassyJim
 Tmp = 0
 TempDate = Date$'Trying to preserve values in case NTP fails (old values OK for now)
 TempTime = TIME$
 DATE$ = "01-04-2000"
 DO
   ON ERROR SKIP
   
   'web ntp 11,"uk.pool.ntp.org"
   WEB NTP Tzone+DST(),"au.pool.ntp.org"
   
   if MM.ERRMSG$ <> "" then
     print MM.ERRMSG$; " skipped"
     DAte$ = TempDate
     Time$ = TempTime
     Exit Do
   End If
   IF DATE$ = "01-04-2000" THEN
     PRINT "NTP Timed out. Tmp = ";Tmp
     PRINT #1, "NTP Timed out"
   End If
   INC Tmp
 LOOP UNTIL DATE$ <>"01-04-2000" OR Tmp > 4
 'NTP automatically sets DATE$ and TIME$
 
 If Tmp > 4 then DAte$ = TempDate
 print Date$; "  "; Time$
End Sub 'Get_NTP
 
FUNCTION DST()  'Ex TassyJim
 LOCAL integer daynumnow, aprstart, octstart, dst1, dst2
 local string dateNow$
 
 dateNow$ = DATE$
 daynumnow = EPOCH(datenow$+" 00:00:00")/86400
 aprstart = EPOCH("01-04-"+MID$(dateNow$,7,4)+" 00:00:00")/86400
 dst1 = 3-(aprstart MOD 7)
 dst1 = aprstart+dst1 ' first sunday in april in current year
 
 octstart = EPOCH("01-10-"+MID$(dateNow$,7,4)+" 00:00:00")/86400
 dst2 = 3-(octstart MOD 7)
 dst2 = octstart+ dst2 ' first sunday in october in current year
 
 PRINT DATETIME$(dst1*86400) ' for debug
 PRINT DATETIME$(dst2*86400)
 IF daynumnow < dst1 OR daynumnow >= dst2 THEN ' swap for northern hemisphere
   dst = 1
 ELSE
   dst = 0
 ENDIF
END FUNCTION 'DST
 '
 '
 '

Edited 2023-03-07 11:36 by Andrew_G
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6103
Posted: 01:51am 07 Mar 2023
Copy link to clipboard 
Print this post

Andrew,
I 'think' that once called, NTP will make regular calls to update time without the need for you to do anything.
It just needs to be run once at the start of the program.

In your Get_NTP sub,
you are setting the date to 1-4-2000 and then calling DST(). This means DST will always return TRUE whatever the real date. If that first NTP call works, DST will be here to stay.
You really needs to call NTP first and then if dst() is true, call NTP again with the extra hour added.

I have been trying to come up with an clever way of doing all this, but I am not very clever at the best of times.

dst() really only needs to be run once a day, once the program is under way.
Check and if dst() is the same as yesterday, no need to change anything.

Jim
Edited 2023-03-07 11:56 by TassyJim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 03:19am 07 Mar 2023
Copy link to clipboard 
Print this post

Thanks Jim,
How do I/we confirm that NTP is a once off (just like OPTION WIFI MySSID, MyPassword ?)?
(I'm happy to wait for Pater et al to chime in.)

Yes my Get_NTP Sub (and most of my efforts) is clumsy - and I'm always keen to benefit from others' experience. I have learnt so much from you and TBS.

DST may not be a big issue, because I suspect/hope that when Openweather outputs the weather it includes DST in its ". . . "timezone":39600, . . ." output. I can make use of that!
Don't ask me how it knows that my State, and yours, has DST whereas Qld doesn't.

My test code (as above) has survived longer than previous efforts with no "Panic" crashes yet - so I wonder if the frequent and almost coincident NTP calls were a problem?

I'll keep testing.

Cheers,

Andrew
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3816
Posted: 08:37am 07 Mar 2023
Copy link to clipboard 
Print this post

  RonnS said  example for an Radio stream :

http://www.beatlesradio.com:8000/stream
or
http://81.17.57.158:24929/stream


For me those are MPEG so looks like you're asking for an MPEG-decoder (as well as the net stuff).

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 08:39am 07 Mar 2023
Copy link to clipboard 
Print this post

WEB NTP executes once only. You need to call it again if you want to update the clock. Note however the Pico xtal appears to be very stable and accurate so once a day should be enough
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 09:03am 07 Mar 2023
Copy link to clipboard 
Print this post

Thanks Peter.
Just to clarify that Jim's 'thought' of a regular update is not quite correct but that once a day is more than accurate for the simple time stamp stuff I want to use it for.

I am hoping to have a Pico-W back to back with a Pico with common Vbus (5V) and Gnd and serial comms via GP00/GP01 on each.
The Pico-W will do all the WWW stuff and send the data (including TIME$ etc) to the Pico. The Pico will use GUI commands to display it all and pass limited commands (eg to get Openweather NOW!) to the Pico-W.

Given the sensitivities of sharing a USB hub that Jim has observed I'll need to be careful to program the two Picos separately but run them off a common supply.
Well that's the plan . . .

Your work on the Pico-W makes it possible.

Cheers,

Andrew
 
     Page 1 of 2    
Print this page
© JAQ Software 2024