Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 03:31 28 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 : WebMite MQTT

     Page 1 of 2    
Author Message
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 05:30pm 13 Jul 2023
Copy link to clipboard 
Print this post


Hi Peter,

a couple of questions about MQTT. Can I find out via WEBMITE how long the keep alive time is on the server?
And do I have to keep the connection alive by sending data? Or does the MQTT implementation of WebMite do that, because then only 2 bytes are sent?

Background: I made my first steps with the protocol and the "MQTT Mosquitto Broker" in the "Home Assistant" server. After a while it stopped accepting my data from the sensor. If I send it every 2 seconds, as in the example, everything is fine, but every 10 minutes it does not like it. On the internet I read something about 30-45 seconds ...

Then I looked at the specification, but I can only understand half of it. And I read about the ping to get the connection.

http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180894

I hope you can shed some light on this.

Matthias



Keep Alive value

[MQTT-3.1.2-23]
It is the responsibility of the Client to ensure that the interval between Control Packets being sent does not exceed the Keep Alive value. In the absence of sending any other Control Packets, the Client MUST send a PINGREQ Packet.

[MQTT-3.1.2-24]
If the Keep Alive value is non-zero and the Server does not receive a Control Packet from the Client within one and a half times the Keep Alive time period, it MUST disconnect the Network Connection to the Client as if the network had failed.

 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 05:13pm 27 Jul 2023
Copy link to clipboard 
Print this post


> option list
WebMite MMBasic Version 5.07.07
OPTION AUTORUN ON
OPTION COLOURCODE ON
OPTION WIFI behofam, *****************
OPTION TCP SERVER PORT 80
OPTION TELNET CONSOLE ON


Ok, with this workaround I thought I had solved the problem of the MQTT broker not receiving data from the WebMite. But unfortunately it is still not stable. I also bought the "Delock Power Socket Switch MQTT Power Monitoring Plug (11827)" to have
another MQTT transmitter. This one doesn't cause any problems, so I can rule out any problems with the server.


'gas impulse counter
WEB mqtt close
WEB mqtt connect "192.168.1.137", 1883, "mqtt", "****" ', mymqttint
' WEB mqtt subscribe "gascount-beho"
'
SetTick 30000,myping
'
Dim i=0, c=0, z=0
Dim gc!=1009.64+(0.01*(84+63)) '12.7.23 +16.7. +19.7 !25.7. neustart
SetPin gp9, din, pullup
i=Pin(gp9)
Print "Start:";Time$, "Impuls:";i, "Count:";c, gc!
value$="{ "+Chr$(34)+"m3"+Chr$(34)+": "+Str$(gc!)+" }"
WEB mqtt publish "gascount-beho",value$
Do
 If i<>Pin(gp9) Then
   i=Pin(gp9)
   If i=1 Then
     c=c+1
     gc!=gc!+0.01
   EndIf
   Print Time$, "Impuls:";i, "Count:";c, gc!
   value$="{ "+Chr$(34)+"m3"+Chr$(34)+": "+Str$(gc!)+" }"
   WEB mqtt publish "gascount-beho",value$
   Print value$
 EndIf
 u$=Inkey$
 If u$="u" Then
   Print "Update: ";Time$, "Impuls:";i, "Count:";c, gc!
   Print value$
 EndIf
 If u$="m" Then
   value$="{ "+Chr$(34)+"m3"+Chr$(34)+": "+Str$(gc!)+" }"
   WEB mqtt publish "gascount-beho",value$
   Print "m",Time$,value$
 EndIf
Loop
'
Sub myping
 z=z+1
 If z>120 Then
   z=0
   WEB mqtt close
   WEB mqtt connect "192.168.1.137", 1883, "mqtt", "****"
 EndIf
 value$="{ "+Chr$(34)+"m3"+Chr$(34)+": "+Str$(gc!)+" }"
 WEB mqtt publish "gascount-beho",value$
 Print "m",Time$,value$
End Sub
'
Sub mm.startup
 WEB ntp +2,"192.168.1.1"
End Sub


What definitely causes the WebMite to crash in the MQTT area is a WLAN interruption. After restoring the WLAN, with Putty the WebMite is accessible via Telnet, but the MQTT telegrams are no longer sent or the broker receives nothing. The Delock keeps on sending and the server keeps on receiving.

Can there still be a problem in the MQTT program part of the WebMite?

I ask for help, thanks!
Matthias
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 09:02pm 28 Jul 2023
Copy link to clipboard 
Print this post

Matthias,
I was happy to see your original post because I had the same (similar?) problem and question.  I tried a "hack" that just resubscribes to the MQTT broker every 60 seconds and it seemed to work.  But I would prefer to use the official methods to do this. There is mention of PINGREQ and PINGRESP commands but I don't know if MMBASIC incorporates these or any other mechanism for "keep alive" the MQTT subscription.

You asked a good question and I was surprised no one answered. Hopefully this will help.  (The broker I am using is BeeBotte.)

Sorry I didn't provide this on your first request.

Greg
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 06:04pm 29 Jul 2023
Copy link to clipboard 
Print this post

Hi Greg,

Thanks for your message. Others seem to be having problems with MQTT as well:
https://www.thebackshed.com/forum/ViewTopic.php?TID=15885&P=3#203933

I am using the "Mosquitto Broker" version: 6.2.1 as an add-on in the "Home Assistant".

There is a PDF book_1-5.pdf by user "pwillard" which describes MQTT on page 9.
https://www.thebackshed.com/forum/ViewTopic.php?TID=15637&PID=198926#198926#198926
Unfortunately, there is nothing more detailed and it seems to be no longer maintained.

It's a shame that some topics are spread all over the forum.

Actually, only Peter can help us here. Let's just wait and see.

Many greetings
Matthias

Edited 2023-07-30 04:05 by homa
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 06:14pm 29 Jul 2023
Copy link to clipboard 
Print this post


It seems to work fine for some people!
https://www.thebackshed.com/forum/ViewTopic.php?TID=15608&PID=198532#198532#198634
Hi @Luc, can you comment on this?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9128
Posted: 09:04am 30 Jul 2023
Copy link to clipboard 
Print this post

Have you looked at the bug list for 5.07.07? There is a known memory leak with mqtt. Fixed in the latest betas
 
homa

Guru

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

  matherp said  Have you looked at the bug list for 5.07.07? There is a known memory leak with mqtt. Fixed in the latest betas

No.
Funny, I went back from 5.07.08b2 to the official release version. I will install the latest beta now and report back ...
Can you comment on the other questions as well?
Thanks a lot!
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 04:27pm 02 Aug 2023
Copy link to clipboard 
Print this post


OK, the first attempt with 5.07.08b9 didn't last 24 hours. But it was enough to connect with Putty via telnet, then close the running programme and simply restart it via run. The workaround with close and open in the programme was not enough? So far, the values arrive in the MQTT broker.  

@Greg, how are things going with you? Have you also used a new version?

Matthias
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 04:50pm 02 Aug 2023
Copy link to clipboard 
Print this post

@Matthias: It was only yesterday that I loaded 5.07.08b9.  But it is working as before.  We may be using the WebMite's MQTT capabilty differently.  I'm using it as a client to send data periodically to an outside broker.  If you are using it as a broker, I probably don't have any relevant experience to offer.  If your usage is similar to mine, I would be happy to share my experience and methods.  I do find that the different brokers work in different ways.
Greg
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9128
Posted: 06:02pm 02 Aug 2023
Copy link to clipboard 
Print this post

I've just dug into the mqtt source and in theory the client will send a keep-alive message every 100 seconds.
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 06:09pm 02 Aug 2023
Copy link to clipboard 
Print this post

Reviewing your posts, it looks like you are using the Webmite as a client and sending data to Mosquitto as a broker.  Is that right?
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 06:49pm 02 Aug 2023
Copy link to clipboard 
Print this post

  gghh said  Reviewing your posts, it looks like you are using the Webmite as a client and sending data to Mosquitto as a broker.  Is that right?

Yes.
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 06:51pm 02 Aug 2023
Copy link to clipboard 
Print this post

  matherp said  I've just dug into the mqtt source and in theory the client will send a keep-alive message every 100 seconds.

Good to know. Thank you.
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 09:38pm 02 Aug 2023
Copy link to clipboard 
Print this post



  homa said  
  matherp said  I've just dug into the mqtt source and in theory the client will send a keep-alive message every 100 seconds.

Good to know. Thank you.


Unfortunately I don't see this in Wireshark!

My little test programme:

WEB mqtt close
WEB mqtt connect "192.168.1.137", 1883, "mqtt", "*******"
SetTick 60000,mymqtt
Dim test$
'
Do
Loop
'
Sub mymqtt
test$=Time$
Print "sende:";test$,
value$="{ "+Chr$(34)+"test"+Chr$(34)+": "+test$+" }"
WEB mqtt publish "homa-test",value$
Print value$
End Sub


At 60 seconds, everything looks good ...


I don't see a keep-alive signal after 180 seconds ... Instead, the system tells me that the connection has been closed.





Edited 2023-08-03 07:41 by homa
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9128
Posted: 07:27am 03 Aug 2023
Copy link to clipboard 
Print this post

  Quote  I don't see a keep-alive signal after 180 seconds .


You haven't had 100 seconds of inactivity so won't see a keep-alive
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 07:50am 03 Aug 2023
Copy link to clipboard 
Print this post

Certainly. I changed the SetTick beforehand for the 180 seconds

I also get an error message. How can I record this in the programme? At the latest then I can react with a "close/open" and the message is sent. And received by the broker.
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 08:58am 03 Aug 2023
Copy link to clipboard 
Print this post


Hi Peter,
I have now recorded a complete test run without the MQTT filter.
It seems that the Keep-Alive is not recognised as an MQTT protocol by Wireshark, but only as a TCP protocol.
So you are right!
But this must be faulty
, because shortly afterwards the MQTT message comes out of the programme (10:42:52)! But this is rejected by the broker server.
The close/open helps in the running programme, as you can then see.
Matthias


> option list
WebMite MMBasic Version 5.07.08b10
OPTION COLOURCODE ON
OPTION WIFI behofam, *****************, PICOE6614104033
OPTION TELNET CONSOLE ON


WEB mqtt close
WEB mqtt connect "192.168.1.137", 1883, "mqtt", "*******"
SetTick 1000,mysec
'
Dim t=0
Dim test$
'
Do
Select Case t
 Case 0, 30, 90, 180, 360, 370
  mymqtt
 Case 380
  WEB mqtt close
  WEB mqtt connect "192.168.1.137", 1883, "mqtt", "*******"
  mymqtt
 Case 390, 400, 410
  mymqtt
End Select
Loop
'
Sub mymqtt
test$=Time$
Print : Print "sende:";test$,
value$="{ "+Chr$(34)+"test"+Chr$(34)+": "+test$+" }"
WEB mqtt publish "homa-test",value$
Print value$
t=t+1
End Sub
'
Sub mysec
t = t + 1
Print ".";
End Sub


Connecting to 192.168.1.137 port 1883

sende:10:36:56  { "test": 10:36:56 }
.............................
sende:10:37:25  { "test": 10:37:25 }
...........................................................
sende:10:38:24  { "test": 10:38:24 }
.........................................................................................
sende:10:39:53  { "test": 10:39:53 }
...................................................................................................................................................................................
sende:10:42:52  mqtt_publish: TCP disconnected{ "test": 10:42:52 }
.........
sende:10:43:01  mqtt_publish: TCP disconnected{ "test": 10:43:01 }
.........Connecting to 192.168.1.137 port 1883

sende:10:43:10  { "test": 10:43:10 }
.........
sende:10:43:19  { "test": 10:43:19 }
.........
sende:10:43:28  { "test": 10:43:28 }
.........
sende:10:43:37  { "test": 10:43:37 }
.............................................


1 0.000000 192.168.1.113 192.168.1.137 TCP 105 59939 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
2 0.000171 192.168.1.113 192.168.1.137 TCP 105 [TCP Retransmission] 59939 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
3 0.000506 192.168.1.137 192.168.1.113 TCP 107 1883 → 59939 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
4 0.000757 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
5 0.007415 192.168.1.113 192.168.1.137 MQTT 156 Connect Command
6 0.007763 192.168.1.113 192.168.1.137 TCP 156 [TCP Retransmission] 59939 → 1883 [PSH, ACK] Seq=1 Ack=1 Win=16384 Len=55
7 0.007959 192.168.1.137 192.168.1.113 TCP 107 1883 → 59939 [ACK] Seq=1 Ack=56 Win=64185 Len=0
8 0.008109 192.168.1.137 192.168.1.113 TCP 107 [TCP Dup ACK 7#1] 1883 → 59939 [ACK] Seq=1 Ack=56 Win=64185 Len=0
9 0.009041 192.168.1.137 192.168.1.113 MQTT 107 Connect Ack
10 0.009188 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=1 Ack=56 Win=64185 Len=4
11 0.015612 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=1) [homa-test]
12 0.015788 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59939 → 1883 [PSH, ACK] Seq=56 Ack=5 Win=16380 Len=35
13 0.019445 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=1)
14 0.019573 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
15 0.229427 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
16 0.229595 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
17 0.229754 192.168.1.113 192.168.1.137 TCP 101 59939 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
18 0.229890 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 17#1] 59939 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
19 0.231836 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 17#2] 59939 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
20 0.231897 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 17#3] 59939 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
29 20.556443 192.168.1.113 192.168.1.1 DHCP 397 DHCP Request  - Transaction ID 0x9d96a37
30 20.556605 192.168.1.113 192.168.1.1 DHCP 397 DHCP Request  - Transaction ID 0x9d96a37
31 20.556755 192.168.1.1 192.168.1.113 DHCP 389 DHCP ACK      - Transaction ID 0x9d96a37
32 20.556907 192.168.1.1 192.168.1.113 DHCP 389 DHCP ACK      - Transaction ID 0x9d96a37
33 29.016386 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=2) [homa-test]
34 29.016551 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59939 → 1883 [PSH, ACK] Seq=91 Ack=9 Win=16376 Len=35
35 29.017519 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=2)
36 29.017689 192.168.1.137 192.168.1.113 MQTT 107 [TCP Fast Retransmission] , Publish Ack (id=2)
37 29.231347 192.168.1.113 192.168.1.137 TCP 101 59939 → 1883 [ACK] Seq=126 Ack=13 Win=16372 Len=0
38 29.231498 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 37#1] 59939 → 1883 [ACK] Seq=126 Ack=13 Win=16372 Len=0
39 88.017191 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=3) [homa-test]
40 88.017354 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59939 → 1883 [PSH, ACK] Seq=126 Ack=13 Win=16372 Len=35
41 88.018338 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=3)
42 88.018503 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=13 Ack=161 Win=64080 Len=4
43 88.231058 192.168.1.113 192.168.1.137 TCP 101 59939 → 1883 [ACK] Seq=161 Ack=17 Win=16368 Len=0
44 88.231099 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 43#1] 59939 → 1883 [ACK] Seq=161 Ack=17 Win=16368 Len=0
53 177.018982 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=4) [homa-test]
54 177.019138 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59939 → 1883 [PSH, ACK] Seq=161 Ack=17 Win=16368 Len=35
55 177.020070 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=4)
56 177.020225 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [PSH, ACK] Seq=17 Ack=196 Win=64045 Len=4
57 177.232744 192.168.1.113 192.168.1.137 TCP 101 59939 → 1883 [ACK] Seq=196 Ack=21 Win=16364 Len=0
58 177.232744 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 57#1] 59939 → 1883 [ACK] Seq=196 Ack=21 Win=16364 Len=0
67 320.562070 192.168.1.113 192.168.1.1 DHCP 397 DHCP Request  - Transaction ID 0x9d96a37
68 320.562248 192.168.1.113 192.168.1.1 DHCP 397 DHCP Request  - Transaction ID 0x9d96a37
69 320.562420 192.168.1.1 192.168.1.113 DHCP 389 DHCP ACK      - Transaction ID 0x9d96a37
70 320.562578 192.168.1.1 192.168.1.113 DHCP 389 DHCP ACK      - Transaction ID 0x9d96a37
71 331.026991 192.168.1.137 192.168.1.113 TCP 107 1883 → 59939 [FIN, ACK] Seq=21 Ack=196 Win=64045 Len=0
72 331.027165 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59939 [FIN, ACK] Seq=21 Ack=196 Win=64045 Len=0
73 331.029429 192.168.1.113 192.168.1.137 TCP 101 59939 → 1883 [FIN, ACK] Seq=196 Ack=22 Win=16363 Len=0
74 331.029429 192.168.1.113 192.168.1.137 TCP 101 [TCP Retransmission] 59939 → 1883 [FIN, ACK] Seq=196 Ack=22 Win=16363 Len=0
75 331.029567 192.168.1.137 192.168.1.113 TCP 107 1883 → 59939 [ACK] Seq=22 Ack=197 Win=64045 Len=0
76 331.029729 192.168.1.137 192.168.1.113 TCP 107 [TCP Dup ACK 75#1] 1883 → 59939 [ACK] Seq=22 Ack=197 Win=64045 Len=0
77 374.021318 192.168.1.113 192.168.1.137 TCP 105 59940 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
78 374.021681 192.168.1.113 192.168.1.137 TCP 105 [TCP Retransmission] 59940 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
79 374.021927 192.168.1.137 192.168.1.113 TCP 107 1883 → 59940 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
80 374.022082 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
81 374.023621 192.168.1.113 192.168.1.137 MQTT 156 Connect Command
82 374.024000 192.168.1.113 192.168.1.137 TCP 156 [TCP Retransmission] 59940 → 1883 [PSH, ACK] Seq=1 Ack=1 Win=16384 Len=55
83 374.024171 192.168.1.137 192.168.1.113 TCP 107 1883 → 59940 [ACK] Seq=1 Ack=56 Win=64185 Len=0
84 374.024334 192.168.1.137 192.168.1.113 TCP 107 [TCP Dup ACK 83#1] 1883 → 59940 [ACK] Seq=1 Ack=56 Win=64185 Len=0
85 374.046228 192.168.1.137 192.168.1.113 MQTT 107 Connect Ack
86 374.046419 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=1 Ack=56 Win=64185 Len=4
87 374.061582 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=1) [homa-test]
88 374.061755 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59940 → 1883 [PSH, ACK] Seq=56 Ack=5 Win=16380 Len=35
89 374.061916 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=1)
90 374.062077 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
91 374.261228 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
92 374.262083 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=5 Ack=91 Win=64150 Len=4
93 374.265566 192.168.1.113 192.168.1.137 TCP 101 59940 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
94 374.265650 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 93#1] 59940 → 1883 [ACK] Seq=91 Ack=9 Win=16376 Len=0
103 383.022694 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=2) [homa-test]
104 383.022866 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59940 → 1883 [PSH, ACK] Seq=91 Ack=9 Win=16376 Len=35
105 383.023701 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=2)
106 383.023867 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=9 Ack=126 Win=64115 Len=4
107 383.270973 192.168.1.113 192.168.1.137 TCP 101 59940 → 1883 [ACK] Seq=126 Ack=13 Win=16372 Len=0
108 383.271124 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 107#1] 59940 → 1883 [ACK] Seq=126 Ack=13 Win=16372 Len=0
109 392.023841 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=3) [homa-test]
110 392.023995 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59940 → 1883 [PSH, ACK] Seq=126 Ack=13 Win=16372 Len=35
111 392.024825 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=3)
112 392.024979 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=13 Ack=161 Win=64080 Len=4
113 392.271140 192.168.1.113 192.168.1.137 TCP 101 59940 → 1883 [ACK] Seq=161 Ack=17 Win=16368 Len=0
114 392.271313 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 113#1] 59940 → 1883 [ACK] Seq=161 Ack=17 Win=16368 Len=0
115 401.022865 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=4) [homa-test]
116 401.023011 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59940 → 1883 [PSH, ACK] Seq=161 Ack=17 Win=16368 Len=35
117 401.023973 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=4)
118 401.024136 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59940 [PSH, ACK] Seq=17 Ack=196 Win=64045 Len=4
119 401.271304 192.168.1.113 192.168.1.137 TCP 101 59940 → 1883 [ACK] Seq=196 Ack=21 Win=16364 Len=0
120 401.271501 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 119#1] 59940 → 1883 [ACK] Seq=196 Ack=21 Win=16364 Len=0

Edited 2023-08-03 19:00 by homa
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9128
Posted: 09:25am 03 Aug 2023
Copy link to clipboard 
Print this post

The pico sends a MQTT_MSG_TYPE_PINGREQ and presumably should then expect a MQTT_MSG_TYPE_PINGRESP.

Perhaps your broker can't handle PINGREQ wheras the broker gghh is using looks like it does

     /* If time for a keep alive message to be sent, transmission has been idle for keep_alive time */
     if ((client->cyclic_tick * MQTT_CYCLIC_TIMER_INTERVAL) >= client->keep_alive) {
       LWIP_DEBUGF(MQTT_DEBUG_TRACE, ("mqtt_cyclic_timer: Sending keep-alive message to server\n"));
       if (mqtt_output_check_space(&client->output, 0) != 0) {
         mqtt_output_append_fixed_header(&client->output, MQTT_MSG_TYPE_PINGREQ, 0, 0, 0, 0);
         client->cyclic_tick = 0;
       }
     } else {
       client->cyclic_tick++;
     }
 
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 351
Posted: 12:10pm 03 Aug 2023
Copy link to clipboard 
Print this post

Hi Peter,

The MQTT broker (https://mosquitto.org/ ) i use supports PINGREQ.

Is it possible that this is a BUG in WebMite?
I have reduced the test program again.

1) connect to MQTT server
2) after 10 seconds a MQTT message
3) wait! and after about 150 seconds the PINGREQ/PINGRESP TCP messages? *
4) after another 10 seconds the next MQTT message. But instead the message "mqtt_publish: TCP disconnected" AND no TCP messages in WireShark!!!!

Maybe the bug is that a status is set incorrectly in MMbasic and the interpreter does not realise that it is still allowed to send? Where else would the error message come from?
Can you please check this in the source code? Thanks a lot!


Matthias


*Addendum:
I just see that after the 150 seconds the connection from the server (192.168.1.137) to the client (.113) is established! Is it possible that this is the disconnect message? (YES! see screenshot.) Then PINGREQ/PINGRESP would definitely be missing in beta10.



(1)
1 0.000000 192.168.1.113 192.168.1.137 TCP 101 59941 → 1883 [FIN, ACK] Seq=1 Ack=1 Win=16376 Len=0
2 0.000000 192.168.1.113 192.168.1.137 TCP 101 [TCP Retransmission] 59941 → 1883 [FIN, ACK] Seq=1 Ack=1 Win=16376 Len=0
3 0.000618 192.168.1.137 192.168.1.113 TCP 107 1883 → 59941 [FIN, ACK] Seq=1 Ack=2 Win=64148 Len=0
4 0.000748 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59941 [FIN, ACK] Seq=1 Ack=2 Win=64148 Len=0
5 0.002740 192.168.1.113 192.168.1.137 TCP 105 59942 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
6 0.003069 192.168.1.113 192.168.1.137 TCP 105 [TCP Retransmission] 59942 → 1883 [SYN] Seq=0 Win=16384 Len=0 MSS=1460
7 0.003293 192.168.1.137 192.168.1.113 TCP 107 1883 → 59942 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
8 0.003440 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [SYN, ACK] Seq=0 Ack=1 Win=64240 Len=0 MSS=1460
9 0.009186 192.168.1.113 192.168.1.137 TCP 101 59941 → 1883 [ACK] Seq=2 Ack=2 Win=16375 Len=0
10 0.009546 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 9#1] 59941 → 1883 [ACK] Seq=2 Ack=2 Win=16375 Len=0
11 0.009935 192.168.1.113 192.168.1.137 MQTT 157 Connect Command
12 0.010139 192.168.1.113 192.168.1.137 TCP 157 [TCP Retransmission] 59942 → 1883 [PSH, ACK] Seq=1 Ack=1 Win=16384 Len=56
13 0.010310 192.168.1.137 192.168.1.113 TCP 107 1883 → 59942 [ACK] Seq=1 Ack=57 Win=64184 Len=0
14 0.010439 192.168.1.137 192.168.1.113 TCP 107 [TCP Dup ACK 13#1] 1883 → 59942 [ACK] Seq=1 Ack=57 Win=64184 Len=0
15 0.010960 192.168.1.137 192.168.1.113 MQTT 107 Connect Ack
16 0.011126 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [PSH, ACK] Seq=1 Ack=57 Win=64184 Len=4
17 0.237845 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [PSH, ACK] Seq=1 Ack=57 Win=64184 Len=4
18 0.237845 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [PSH, ACK] Seq=1 Ack=57 Win=64184 Len=4
19 0.239745 192.168.1.113 192.168.1.137 TCP 101 59942 → 1883 [ACK] Seq=57 Ack=5 Win=16380 Len=0
20 0.239745 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 19#1] 59942 → 1883 [ACK] Seq=57 Ack=5 Win=16380 Len=0

(2)
21 10.016971 192.168.1.113 192.168.1.137 MQTT 136 Publish Message (id=1) [homa-test]
22 10.017126 192.168.1.113 192.168.1.137 TCP 136 [TCP Retransmission] 59942 → 1883 [PSH, ACK] Seq=57 Ack=5 Win=16380 Len=35
23 10.020780 192.168.1.137 192.168.1.113 MQTT 107 Publish Ack (id=1)
24 10.020944 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [PSH, ACK] Seq=5 Ack=92 Win=64149 Len=4
25 10.258225 192.168.1.113 192.168.1.137 TCP 101 59942 → 1883 [ACK] Seq=92 Ack=9 Win=16376 Len=0
26 10.258369 192.168.1.113 192.168.1.137 TCP 101 [TCP Dup ACK 25#1] 59942 → 1883 [ACK] Seq=92 Ack=9 Win=16376 Len=0

(3)
35 162.010442 192.168.1.137 192.168.1.113 TCP 107 1883 → 59942 [FIN, ACK] Seq=9 Ack=92 Win=64149 Len=0
36 162.010644 192.168.1.137 192.168.1.113 TCP 107 [TCP Retransmission] 1883 → 59942 [FIN, ACK] Seq=9 Ack=92 Win=64149 Len=0
37 162.012541 192.168.1.113 192.168.1.137 TCP 101 59942 → 1883 [FIN, ACK] Seq=92 Ack=10 Win=16375 Len=0
38 162.012616 192.168.1.113 192.168.1.137 TCP 101 [TCP Retransmission] 59942 → 1883 [FIN, ACK] Seq=92 Ack=10 Win=16375 Len=0
39 162.012839 192.168.1.137 192.168.1.113 TCP 107 1883 → 59942 [ACK] Seq=10 Ack=93 Win=64148 Len=0
40 162.013073 192.168.1.137 192.168.1.113 TCP 107 [TCP Dup ACK 39#1] 1883 → 59942 [ACK] Seq=10 Ack=93 Win=64148 Len=0

(4)     ???



> run
Connecting to 192.168.1.137 port 1883               <== (1)
..........
sende:12:47:49  { "test": 12:47:49 }                <== (2)
......................................................................................................................................
..........................................................................................<== (3) ......
sende:12:51:39  mqtt_publish: TCP disconnected{ "test": 12:51:39 }    <== (4 - nothing!)
.................
>




Edited 2023-08-03 22:27 by homa
 
gghh
Newbie

Joined: 07/03/2023
Location: United States
Posts: 13
Posted: 12:45pm 03 Aug 2023
Copy link to clipboard 
Print this post

About two months ago I found that I could keep alive my MQTT connection by subscribing every 60 seconds.  That is why mine works.  However, after yesterdays explanations, and knowing that changes were done to the MQTT function recently, I will remove my "re-subscribes" and see if the built-in PINGREQ's do the job with my broker.  I'll keep you posted on what I find out.

@Matherp:  Thanks so much for the explanations recently.  This is such a great feature for the WebMite and I'm glad that the "KeepAlive" function is incorporated.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024