Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:39 27 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 : mmqtt_publish:TCP Disconnected

     Page 2 of 2    
Author Message
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 12:17pm 24 Nov 2023
Copy link to clipboard 
Print this post

Sounds like the WiFi chip remembers the IP addr.

One for Peter? (does it remember it? can it be cleared?)

John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6099
Posted: 07:30pm 24 Nov 2023
Copy link to clipboard 
Print this post

DHCP will remember the address until it's lease time is up and the renew fails.
Then what happens can vary.

Leases times can be anything from a few minutes to hours.

Relying on a 'valid' IP address to indicate maintained connectivity is not a good idea.

Jim
VK7JH
MMedit   MMBasic Help
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 07:45pm 24 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Is DHCP involved on the Pico ? , because if it isn't, then note that the Rpi-Zero and the
hotspot it provides is powered off.

I would love to hear how else I can check with MMBasic commands if there is a connection available ?
Shame we don't have a "Shell" or Ping command.

After sunset the Zero will go off (to conserve power) but the Pico will run 24/7 and keep calculating A/H usage.
So the pico is going to lose the connection, and I have to stop trying to connect.
In situ, I can check the time and include that in the decision, but prefer to have confirmation that the hotspot is not available.

EDit: Is there library code available.
  Quote  Note that any code in the library that is not contained within a subroutine or
function will be executed immediately before a program is run. This can be
used to initialise constants, set options, etc.
Reading the "Connecting to the Internet with the Raspberry Pi W" there are C/C++ functions such as:
  Quote  The values returned by the wlan.status() call are defined in the CYW43 wireless driver, and are passed directly through to
user-code

Edited 2023-11-25 06:06 by Dinosaur
Regards
Hervey Bay Qld.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6099
Posted: 08:19pm 24 Nov 2023
Copy link to clipboard 
Print this post

I am only going on the information you provided.
  Quote  Option Wifi "Rpi-Hotspot","111111111"

(Password changed because I prefer not to advertise)

That tells me that you are using DHCP to get the IP from your hotspot.
I have no idea how long the lease is. That is up to your hotspot.
On my home network leases are valid for 1 hour.
This usually means the client will renew it's lease in half that time - 30 minutes.

When that renewal fails is when you know there is a problem.
If your hotspot issues leases for 24 hours, a client won't try and renew for a long time.

Checking the IP is good when you first connect but not much use later on.

Jim
VK7JH
MMedit   MMBasic Help
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 08:30pm 24 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Thanks for your patience Jim.
Sometime I can't see the wood for the trees.

In one of the earlier posts it was mentioned that some of the Wifi commands needed a connection before they would work.
That discouraged me, and I started thinking of more complicated solutions. MISTAKE, think of simpler solutions.

So, going over your earlier posts again, on MM.INFO(Wifi Status) decided to try.

Lo and behold that does work.
It returns -3 if the Hotspot is down and +1 when it is connected.

One again many thanks for your assistance, I am learning along the way.

PS: I normally edit the password to "*******" but forgot that time,
although I am not connecting to the Internet.
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 12:09am 26 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Am I correct in my testing, that when the "OPTION WIFI SSID$, PassWd$" fails after power down
there is no way to establish a connection once you are in your program ?

If I establish the Hotspot after the program has started, then the WIFI Status is always < 0
Regards
Hervey Bay Qld.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 03:03am 26 Nov 2023
Copy link to clipboard 
Print this post

On WebMite 5.07.08RC21 all I can see is to keep looking for the address until there is a response then use CPU RESTART. It then connects.
Eg.
Do While MM.Info(IP ADDRESS)<>"192.168.1.101"
  Pause 1000
Loop
CPU restart

As long as all important data is is saved to a file (or VAR SAVE) first it can be recovered after the re-boot.

Edit
Perhaps you need WEB SCAN, not MM.Info(IP ADDRESS)
Not Tested
Some experimenting will be needed.
Edited 2023-11-26 13:22 by phil99
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 04:33am 26 Nov 2023
Copy link to clipboard 
Print this post

Hi All

Good call Phil.
I had already tested WEB SCAN and once the SSID was visible, tried a number of ways to connect.
WEB MQTT CONNECT replies with "Wifi not connected"
And just for the fun of it WEB TCP CLIENT REQUEST with the same result.

Didn't dawn on me to activate a Restart.

Now each time I do a recalc of A/H I check WEB SCAN.
IF my SSID is visible, then set a flag to do a reboot next time I save my Value.

           If MM.INFO(Wifi Status) > 0 Then
               WifiConnect
             Else
               DIM a%(1024)
               web scan a%()
               longstring print a%()
               if linstr(a%(),"Rpi-Hotspot") then BootFlag = 1
           EndIf
I wonder if this is something that will get implemented in the long run.
Seems a bit archaic to have to do it this way.
Where does one post feature requests for MMEdit ?
Edited 2023-11-26 14:35 by Dinosaur
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

Joined: 12/08/2011
Location: Australia
Posts: 311
Posted: 06:22am 26 Nov 2023
Copy link to clipboard 
Print this post

Hi All

All good now.
Have also "overcome" the problem of not connecting every second boot.
The only way I get repeatability is to use WEB SCAN in combination with MM.INFO(IP ADDRESS).

 DIM A%(1024)
 web scan a%()                     'see if SSID has popped up
 longstring print a%()
 if linstr(a%(),"Rpi-Hotspot") then
     If MM.INFO(IP ADDRESS) = "0.0.0.0" Then  
         Print "Step 0 IP ";MM.INFO(IP Address)  
         Print "Step 0 Reboot"
         CPU RESTART
     EndIF
 EndIF
So whatever was holding the IP address, is being cleared by WEB SCAN.

Regards
Hervey Bay Qld.
 
     Page 2 of 2    
Print this page


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

© JAQ Software 2024