Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:38 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 1 of 2    
Author Message
Dinosaur

Guru

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

Hi All

Just when I thought I have it all sussed, this happens after probably 30 minutes or less
every time.

At first I thought MMCC was responsible, but then connected the two Rpi's without
using a terminal on the Pico and the same thing happened.

It feels like a timeout, but the --help for mosquitto does not mention an adjustable life.
Cutting snippets from the program shows the following sequence.
 
     If MM.INFO(WIFI STATUS) = 1 Then      'Keep coming back here till we succeed
       IP$ = MM.INFO(IP ADDRESS)           'Get my IP address
       Print "0";";";                      'This proves the hanging point, but not the TCP
     EndIf                                 'disconnect.

     WEB MQTT Connect "192.168.0.101", 1883,"Rpi-Hotspot","********",WebInt
     WEB MQTT subscribe "AmpHr"            
     WEB MQTT subscribe "Control"          
     Print "Comm's Initiated"
     '-------------------------------------
     Tyd$ = Time$
     Print Tyd$
     WEB MQTT PUBLISH "AmpHr",Tyd$ , 0 ,1  
     StartTime2 = mSec :Delay2 = 0      
     Print "Time sent ";Tyd$
     Pause 15000
     '--------------------------------------
     WEB MQTT PUBLISH "AmpHr",IP$,0,1    
     Print "IP Sent ";IP$

The Pico sends a message on 30 sec interval and the Zero checks for Messages every 20 sec's.
When it happens, it could take a couple of times of powering down, before it works
and executes the first of the code above.Note I only power the Pico down, the Zero is still
happily trying to get messages.

Once it does, then works well for 30 min(will confirm) and then TCP error ?
Will to put a delay on the Pico startup, giving the Wifi a chance to connect,
but the TCP disconnect is a mystery.
The mosquitto log shows quite a few of the following:
Client auto_******long number******disconnect.
But there are many of them whilst the Pico is still working,

I have system options:
OPTION WIFI SSID$, Passwd$
FLASH SAVE 1
OPTION AUTORUN 1

Does anyone know of a timeout that needs setting ?
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

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

Hi all

There is one problem wit MMCC though.
After 61 lines the screen stops scrolling and showing the last transmission.
Because I am sending an incrementing number, I know that at the moment I am receiving line 160 on the Rpi Zero and is still working ok.

Edit: And I cant Ctrl-C out of the program.If I disconnect and then try to re-connect
I get ttyACM0 Failed.
Edited 2023-11-21 17:45 by Dinosaur
Regards
Hervey Bay Qld.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 07:49am 21 Nov 2023
Copy link to clipboard 
Print this post

What version are you using? There was a memory leak in MQTT which was fixed during V5.07.08 development
 
Dinosaur

Guru

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

Hi All

Using WebmiteV5.07.08RC19
It is worth noting that if you Dis-connect and re-connect the screen will keeps scrolling down beyond the 61 lines.
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

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

Hi All

Need to ask a silly question.

Does MMBasic clear all variables at the start of the program.
Was chasing a weird problem and that didn't solve itself until I cleared
the variable concerned at the start of the program ??
Regards
Hervey Bay Qld.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 05:49pm 21 Nov 2023
Copy link to clipboard 
Print this post

It should do when you use RUN

(And NEW clears the program as well.)

John
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:54pm 21 Nov 2023
Copy link to clipboard 
Print this post

  Quote  It should do when you use RUN

Exactly, however you can be extra certain if you make the first line of the program:-
CLEAR
.
 
Dinosaur

Guru

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

Hi All

The problem mainly happened during stopping and re-starting the program.
But CLEAR is the best solution to guarantee.

I guess I am spoiled by FreeBasic.

Still having problems with Headless bootup and connecting succesfully.
It takes twice ??
Edited 2023-11-22 09:31 by Dinosaur
Regards
Hervey Bay Qld.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6099
Posted: 01:42am 22 Nov 2023
Copy link to clipboard 
Print this post

  Dinosaur said  
Still having problems with Headless bootup and connecting succesfully.
It takes twice ??


You aren't connecting to a Fritzbox by any chance.

My Fritz needs two attempts but my other access-points are first time every time.

Solution is to check the link and force a reboot if needed.

Jim
VK7JH
MMedit   MMBasic Help
 
Dinosaur

Guru

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

Hi All
  Quote  You aren't connecting to a Fritzbox by any chance.

Don't know any Fritz , no.
Rpi-Pico connected to Rpi-Zero W by Wifi only.

The same problem exists if I connect the Pico to the desktop by usb using MMCC.
MMCC connects immediately but when I run it fails & have to reboot the Pico.

It has to be rock solid reliable boot, otherwise it goes into the bin.
After all there is only one other device on the network. (the Zero)
I have tried to connect other devices to the hot-spot and they connect at once.

Currently I am rebooting (Delay driven) but the complication is that the Rpi-Pico boots
much quicker then the Rpi-Zero, so my web checking has to be perfect.

But I will find the solution.
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

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

Hi All

How do I completely erase everything on the Pico.

I have used "Flash Erase All" and followed up with "Flash List" to see that the flash locations are all available. (which they are)

I have re-written the image file.

But still Autorun is ON and it runs my program.
Going to Edit shows it is there, BUT WHERE ?

I am trying to test the comms with a blank Rpi-Pico to prove the connection issue.

Without scouring through every page of the doc's, checking the Program and Data Storage
does not shed light on this. RUN "A:/MyProgram.bas" pops aan error, so I guess it's not there either. ???
Regards
Hervey Bay Qld.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6099
Posted: 06:58am 22 Nov 2023
Copy link to clipboard 
Print this post

option reset *** you may not want to do this. it clears ALL options
option autorun off
flash erase all
var clear
NEW
VK7JH
MMedit   MMBasic Help
 
phil99

Guru

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

If you really want to take it back to factory fresh re-flash with CLEAR_FLASH.UF2
There will be nothing left at all. It is in some of the firmware download zips.
 
Dinosaur

Guru

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

Hi All

Thanks guys.
I have two Pico's and one has nothing loaded and behaves differently with connect/disconnect.
So, need to confirm when both are clear, they are the same.

Then proceed step by step from there.
Regards
Hervey Bay Qld.
 
Dinosaur

Guru

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

Hi All

Barebones Wifi test.
For the sake of impartiality, I hav used another Terminal Emulator.

dinosaur@Desktop:~$ tio --list-devices
/dev/serial/by-id/usb-Raspberry_Pi_Pico_E6614C311B878338-if00
dinosaur@Desktop:~$ tio /dev/serial/by-id/usb-Raspberry_Pi_Pico_E6614C311B878338-if00
[20:15:56.536] tio v2.5
[20:15:56.536] Press ctrl-t q to quit
[20:15:56.536] Connected

> Option Wifi "Rpi-Hotspot","76216770"

[20:16:30.806] Disconnected
[20:16:31.808] Connected
WebMite MMBasic Version 5.07.08RC19
Copyright 2011-2023 Geoff Graham
Copyright 2016-2023 Peter Mather

PICOE6614C311B8 connecting to WiFi...
failed to connect.
> cpu restart

[20:16:44.165] Disconnected
[20:16:45.166] Connected
WebMite MMBasic Version 5.07.08RC19
Copyright 2011-2023 Geoff Graham
Copyright 2016-2023 Peter Mather

PICOE6614C311B8 connecting to WiFi...
Connected 192.168.0.191

SUCCESS
> cpu restart

[20:16:59.973] Disconnected
[20:17:00.975] Connected
WebMite MMBasic Version 5.07.08RC19
Copyright 2011-2023 Geoff Graham
Copyright 2016-2023 Peter Mather

PICOE6614C311B8 connecting to WiFi...
failed to connect.
FAILURE
> cpu restart

[20:17:11.749] Disconnected
[20:17:12.750] Connected
WebMite MMBasic Version 5.07.08RC19
Copyright 2011-2023 Geoff Graham
Copyright 2016-2023 Peter Mather

PICOE6614C311B8 connecting to WiFi...
Connected 192.168.0.191
>
SUCCESS


I have done this many times and ALWAYS takes two goes.
Using "cpu restart" or unplugging makes no difference.
In order to work out if this is a Pico or MMBasic problem, I would have liked to
get an .uf2 image in one of the other languages to see if the problem repeats.

However, no amount of browsing has given me any luck and
I don't want to start playing with a new language.
Unless someone reading this has something I can use.

So now I will test if it is just as repeatable from within my program.
Regards
Hervey Bay Qld.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 10:55am 22 Nov 2023
Copy link to clipboard 
Print this post

What router are you using - I bet I can guess - Fritzbox?
 
Dinosaur

Guru

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

Hi All

  Quote  What router are you using - I bet I can guess - Fritzbox?

As I said to Tassie Jim, I don't know any Fritz.

However, NO ROUTER.
This is a hotspot connection created on the Rpi-Zero W and the Rpi-Pico is the only client.
Regards
Hervey Bay Qld.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9122
Posted: 01:26pm 22 Nov 2023
Copy link to clipboard 
Print this post

Its probably a timing issue. The Pi-zero is too slow to respond until the required code has been read from the sdcard
 
TassyJim

Guru

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

Just put

if not connected
CPU RESTART
endif

in your program.
Together with AUTORUN and the usual watchdog timers and you will have the reliability you are after.

Jim.
VK7JH
MMedit   MMBasic Help
 
Dinosaur

Guru

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

Hi All

I think I have sussed the problem

Using MM.INFO(IP ADDRESS) in any checking of connection is hampered by the fact
that disconnecting,by quitting the program  or powering off the Rpi-Zero that supplies
the hotspot does NOT clear it "0.0.0.0".
So this code that I use:
     If InStr(MM.INFO(IP ADDRESS),"192.168.0.") > 0 Then
         Print MM.INFO(IP Address)
         CommFlag = 1
         Exit Do
       Else
         Print MM.INFO(IP Address)
         If StepNbr = 0 Then                    'Only at original power up
           IF mSec - StartTime > 100 THEN       'if not there by 100mSec
             Print "CPU Restarting"             'even 15 sec's doesn't help
             CPU RESTART                        'so may as well restart.
           EndIf
         EndIf
         Exit Sub
     EndIf
only works if I power down the Pico.
I have a CLEAR statement at the start of the program, but that does not seem to clear it.
Have also tried:MM.INFO(IP ADDRESS) = "0.0.0.0" which does not create an error
but doesn't clear the IP address.

Am I the only one with this problem, or am i missing something.?

Edit: As Jim suggested "RESET" works , but then I have to set all the options again.
I guess there is no batching of these commands before starting the Program.
Edit  again: Even if I could POKE 1 byte to the IP address location in memory,
that would be enough for my code to fail the test.
Edited 2023-11-24 15:23 by Dinosaur
Regards
Hervey Bay Qld.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024