Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 14:26 25 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 : WEB NTP

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 10:21pm 08 Dec 2023
Copy link to clipboard 
Print this post

When getting the time with WEB NTP it often fails the first time. There was a post in a thread about how to overcome this, maybe from TassyJim. On searching I found so many threads on the WebMite it was impossible to find. Can anyone post some code that will ensure the time is set before continuing. This is on my alarm that will send an email if triggered, since it may sit for a long time it would also be useful to update the time occasionally so that the time it triggers is accurate.
Using the code in the manual
ON ERROR SKIP 3
WEB NTP -10
IF MM.ERRNO THEN WEB NTP -10
IF MM.ERRNO THEN PRINT "Failure to connect to the Internet" : CPU RESTART

does check twice but we still cannot be sure the time is set, or will the CPU keep restarting until the time is set. The other problem with this code is that if the time is set at line 3, line 4 is then executed and performs a restart so I've had to comment line 4 out.
Edited 2023-12-09 11:12 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 05:00am 09 Dec 2023
Copy link to clipboard 
Print this post

I have overcome my problem by having an indicator LED flashing once the program is in the main loop, so if the LED is flashing the time must be set.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 05:20am 09 Dec 2023
Copy link to clipboard 
Print this post

Perhaps replace that line with:-
IF MM.ERRNO THEN
  PRINT "Failure to connect to the Internet"
  CPU RESTART
EndIf

It then should then skip the restart if there is no error.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 05:21am 09 Dec 2023
Copy link to clipboard 
Print this post

I prefer to set a specific NTP server - one that is close to me.
Your ISP should have one available.
Your router might be configured as a NTP server. If so that is a good choice.

(I have a GPS derived time server in the shed so that is what I use, either directly or via the router)

You shouldn't have to reboot before attempting to set the time again.

Provided your network is up, you can just run the WEB NTP command again.

You could set the date to something silly "01/04/1999" and once that changes, you know your NTP command worked.


Jim
VK7JH
MMedit   MMBasic Help
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 05:37am 09 Dec 2023
Copy link to clipboard 
Print this post

  palcal said  The other problem with this code is that if the time is set at line 3, line 4 is then executed and performs a restart so I've had to comment line 4 out.

There seems to be something strange going on in the latest WebMite firmware.  ON ERROR SKIP 3 doesn't skip errors on the next 3 lines like it should, instead it appears to act like an ON ERROR SKIP 1 (Peter?).

This should work:
ON ERROR SKIP
WEB NTP -10
IF MM.ERRNO THEN
 ON ERROR SKIP
 WEB NTP -10
 IF MM.ERRNO THEN PRINT "Failure to connect to the Internet" : CPU RESTART
ENDIF


Geoff
Geoff Graham - http://geoffg.net
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 05:56am 09 Dec 2023
Copy link to clipboard 
Print this post

Thanks for that, it gives me a couple of things to look at.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 06:12am 09 Dec 2023
Copy link to clipboard 
Print this post

ON ERROR ok on b2
WebMite MMBasic Version 5.08.08b2
> ON ERROR SKIP 3: x=9/0 :?x
0
> ON ERROR SKIP 3:x=8:x=2: x=9/0 :?x
2
> ON ERROR SKIP 3:x=8:x=2:x=7: x=9/0 :?x
Error : Divide by zero
>
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 08:21am 09 Dec 2023
Copy link to clipboard 
Print this post

  Quote  There seems to be something strange going on in the latest WebMite firmware.  ON ERROR SKIP 3 doesn't skip errors on the next 3 lines like it should, instead it appears to act like an ON ERROR SKIP 1 (Peter?).


That makes no sense as the code is identical to the PicoMite and VGA versions which both work but it is as you say (b4/5)
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1057
Posted: 02:01pm 09 Dec 2023
Copy link to clipboard 
Print this post

Hi

FWIW, I've been playing around with the Modem/Router Watchdog circuit & program from Nov '23 edition of SC mag here p68 .
They basically (pun intended), check an NTP server every 2 minutes & if OK, carry on & loop.
If that fails, the program checks Google & if that fails, checks Microsoft then reboots the Modem/Router (& PICO) if not OK.

I found a few problems with the code etc.

Firstly WEB NTP -10 sets the time to US West Coast time. Should have been just 10 for Queensland time. (GMT +10. Confused me for a bit as the PICO time was way wrong).

Secondly, I was getting dozens of different NTP servers with WEB NTP 10, some which caused the program to crash. I found a Google NTP server (see code below) & had no further problems with this issue when set for that. (Jim mentioned using a single server)

&

Thirdly, the ERROR Codes were not being cleared after an error, so the program went through & rebooted after the first error regardless of the results of the other tests. Adding the ON ERROR CLEAR commands solved that problem (SC advised)  

Below is the SC code along with my (suggested) changes. My actual test program is a bit different in that it uses PAUSE rather than sending the CPU to sleep & it prints out more details of program operation etc & I have left out the ON ERROR IGNORE command near the beginning.

I'm running Ver 5.0708 with no real problems. I have tried a couple of the newer versions, which don't appear to be as stable (PICO locks up). I have not gotten around to test the latest version yet.  

This may or may not help palcal.

'MMBasic Code Listing
WATCHDOG 65000
PRINT “Watchdog initialising”
SETPIN GP22, DOUT
PIN(GP22) = 0
SETPIN GP28, AIN
ON ERROR IGNORE  'not sure on this one
CPU SLEEP 60
DO
 WATCHDOG 65000
 CPU SLEEP 60
 WATCHDOG 200000
 PRINT “Checking NTP”
 'WEB NTP -10    ' Note: GMT -10Hrs
 WEB NTP 10, "216.239.35.0"   'Changed to a Google NTP AEST
 IF MM.ERRNO THEN
   ON ERROR CLEAR   'added
   PRINT “Checking Google”
   WEB OPEN TCP CLIENT “google.com”, 80
   IF MM.ERRNO THEN
     ON ERROR CLEAR   'added
     PRINT “Checking Microsoft”
     WEB OPEN TCP CLIENT “microsoft.com”, 80
     IF MM.ERRNO THEN
      PRINT “Rebooting router”
      PIN(22) = 1
      WATCHDOG 10000
      CPU SLEEP 5
      PIN(22) = 0
      WATCHDOG 200000
      CPU SLEEP 180
      CPU RESTART
    ELSE
     PRINT “OK”
     WEB CLOSE TCP CLIENT
     ENDIF
   ELSE
     PRINT “OK”
     WEB CLOSE TCP CLIENT
   ENDIF
 ELSE
   PRINT “OK”
 ENDIF
 WATCHDOG 65000
 CPU SLEEP 60
LOOP

Brian
ChopperP
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 08:45pm 09 Dec 2023
Copy link to clipboard 
Print this post

Thanks for that Brian, I have the mag. and will read the article. I did realiase the -10 was wrong and changed it. I will try the google server although at the moment it seems to always connect on the second try.
You say you are running Ver 5.0708 I've only got 5.07.07 from Geoff's Site for his Watering System, I didn't know where to find the latest version. Maybe it's in Fruit of the Shed, I'll have a look.
Edited 2023-12-10 07:07 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 09:12pm 09 Dec 2023
Copy link to clipboard 
Print this post

Couldn't find anything there, is there somewhere on the forum for Firmware or do I just search through the threads.
Edit... Found 5.08.00
Edited 2023-12-10 07:27 by palcal
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 09:30pm 09 Dec 2023
Copy link to clipboard 
Print this post

  palcal said  somewhere on the forum for Firmware


The thread, "PicoMite/VGA/Web V5.08.00: back to betas". Latest (at present) here

Be sure to do "OPTION LIST" before "UPDATE FIRMWARE" so that you can recreate your options, which are erased by this update. Also, save anything on drive A: that you will need.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 09:37pm 09 Dec 2023
Copy link to clipboard 
Print this post

Thanks, I found that and have downloaded.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 09:48pm 09 Dec 2023
Copy link to clipboard 
Print this post

MY suggestion for NTP servers, is somewhere close so you are not bouncing around the world.

In Australia, 0.au.pool.ntp.org is good.

Your ISP will be closer to you.
and your router may be easiest but not for testing WWW connectivity.

Jim
VK7JH
MMedit   MMBasic Help
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 11:02pm 09 Dec 2023
Copy link to clipboard 
Print this post

Thanks Jim I've been using au.pool.ntp.org. Everything seems to be working OK as far as the PicoWeb is concerned. Now having a bit of trouble with the RCWL-0516 Radar Sensor, it was working OK, just ordered some more.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 03:49am 10 Dec 2023
Copy link to clipboard 
Print this post



Found out why the Radar Module did not work.There is a cap missing top of photo. I have 5 one is OK one had the cap floating around in the wrapper and 3 had no cap at all.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1873
Posted: 03:04am 12 Dec 2023
Copy link to clipboard 
Print this post

I used the one with cap still attached but still had trouble, I found that whilst the cap was stuck in place it was not connected. I removed it, cleaned and resoldered.
Now working OK. These boards are not very good quality but what can you expect for cheap boards from China.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
pwillard
Senior Member

Joined: 07/06/2022
Location: United States
Posts: 292
Posted: 02:20pm 24 May 2024
Copy link to clipboard 
Print this post

I finally just got tired of NTP not working right, even though I have the latest BETA, it still refuses to work reliably.


So, I installed the NTP service on one of my local Raspberry Pi servers and I use that.  Being a local IP, it just doesn't seem to fail anymore... so that's my solution. Maybe not for everyone... but if you have an always on server like I do, its possible.


web ntp -4, "192.168.1.7"
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1241
Posted: 02:57pm 24 May 2024
Copy link to clipboard 
Print this post

  pwillard said  ... Maybe not for everyone... but if you have an always on server like I do, its possible.

Thanks for the hint. I think I can do the same with my router (Fritzbox).
Best regards
Michael
causality ≠ correlation ≠ coincidence
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 08:35pm 24 May 2024
Copy link to clipboard 
Print this post

  twofingers said  
  pwillard said  ... Maybe not for everyone... but if you have an always on server like I do, its possible.

Thanks for the hint. I think I can do the same with my router (Fritzbox).
Best regards
Michael


Yes.
Using my English language Fritz:
In the Fritz
Under Home Network / Network / Network Settings
Scroll down to "Time Synchronization"
Set The server you want to use and tick in "Make FRITZ!Box available as a time server in the home network"

I have my Fritz pointing to my GPS derived Time server but you can use any Time server as the reference.

Jim
VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024