Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 01:45 17 Nov 2025 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 : UDP

     Page 2 of 2    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3476
Posted: 01:44pm 13 Dec 2020
Copy link to clipboard 
Print this post

  lew247 said  I think I'm going to have to use serial instead


That might be better.

Can you post the text of the three separate UDP messages? I can test them even without an ESP32 set up (I have several).

This works for me:

pi@raspberrypi:~ $ sudo ./mmbasic54 lew03.bas
LINUX MMBasic Version 5.4.25
Copyright 2011-2018 Geoff Graham
Copyright 2011-2018 Peter Mather
> list
Option EXPLICIT
Dim ss$,sec1$,aa$,a1$,a2$,a43$,a50$,b$,c%, sec, tag$
On error skip
UDP close
UDP server 4997
Do
 On error skip
 UDP receive aa$,b$,c%
 If c%>0 Then DECODE
Loop
UDP close

Sub DECODE
 tag$=Mid$(aa$,1,2)
 Select Case tag$
  Case "#1": Print Field$(aa$,3) ' do field extract
  Case "#2": Print Field$(aa$,6) ' do field extract
  Case "#3": ' do field extract
 End Select
End Sub

> run
Cloudy
chance-rain


From another pi I'm sending these UDP messages using netcat:

echo "#1*,cc-cloudy,Cloudy,6.3,993.0,rising,93,1.0,SW,null,1.0,null,5.0,1.74,1.59,Cloudy Rain Likely,rainy,11.0,4.0,80,chance-rain,rain,Rain Likely,rainy,10.0,8.0,70,chance-rain,rain," | netcat -u -w 1 192.168.2.150 4997

echo "#2Rain Possible,possibly-rainy-day,8.0,6.0,40,chance-rain,rain,Rain Likely,rainy,9.0,7.0,70,chance-rain,rain,2.75,3.21,"conditions":"Cloudy","icon":"cloudy","precip_probability":5,"precip_type":"rain","feels_like":5.0,#" | netcat -u -w 1 192.168.2.150 4997
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:02pm 13 Dec 2020
Copy link to clipboard 
Print this post

Serial really hates me just as much
udp.write "192.168.1.20", 4997,"*" + "," + a1$ + "," + a2$ + "," + a3$ + "," + a4$ + "," + a5$ + "," + a6$ + "," + a7$ + "," + a8$ + "," + a9$ + "," + a10$ + "," + a11$ + "," + a12$ + "," + a13$ + "," + a14$ + "," + d1$ + "," + d2$ + "," + d3$ + "," + d4$ + "," + d5$ + "," + d6$ + "," + d7$ + "," + e1$ + "," + e2$ + "," + e3$ + "," + e4$+ "," + "#"  
pause 400
udp.write "192.168.1.20", 4997, "*" + "," + e5$ + "," + e6$ + "," + e7$ + "," + f1$ + "," + f2$ + "," + f3$ + "," + f4$ + "," + f5$ + "," +  f6$ + "," + f7$ + "," +  g1$ + "," + g2$ + "," + g3$ + "," + g4$ + "," + g5$ + "," + g6$ + "," + g7$ + "," + b2$+ "," + c2$  + "," + h1$  + "," + h2$  + "," + h3$  + "," + h4$  + "," + h5$ + "," + "#"


I narrowed it down to 2 UDP sends
and it sends new data every 30 seconds

This is the actual data sent
  Quote  *,cc-rainy,Rain Likely,7.9,979.9,falling,95,6.0,SSE,null,11.0,null,6.0,6.24,1.74,Rain Likely,rainy,10.0,7.0,80,chance-rain,rain,Rain Possible,possibly-rainy-day,9.0,6.0,#

*,40,chance-rain,rain,Rain Likely,rainy,9.0,6.0,60,chance-rain,rain,Rain Likely,rainy,9.0,7.0,50,chance-rain,rain,2.75,3.24,"conditions":"Rain Likely","icon":"rainy","precip_probability":95,"precip_type":"rain","feels_like":6.0,#

Edited 2020-12-14 00:20 by lew247
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:22pm 13 Dec 2020
Copy link to clipboard 
Print this post

I don't actually need any of the *'s or #'s I stupidly thought they would make it easier to receive
The issue is it needs to go into a longstring variable I think but I can't figure out how
and the same with serial, if I send it as one data burst it says string too long
if I try and longstring append it does nothing
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3476
Posted: 03:04pm 13 Dec 2020
Copy link to clipboard 
Print this post

Why remove the tags numbering the UDP transmissions? This lists every field in the two lines you provided above (note that I put a comma after the trailing "#" so that FIELD$ finds it).

Option EXPLICIT
Dim ss$,sec1$,aa$,a1$,a2$,a43$,a50$,b$,c%, sec, tag$, i%
On error skip
UDP close
UDP server 4997
Do
 On error skip
 UDP receive aa$,b$,c%
 If c%>0 Then DECODE
Loop
UDP close

Sub DECODE
 tag$=Mid$(aa$,1,2)
 Select Case tag$
  Case "#1": LISTFIELDS ' do field extract
  Case "#2": LISTFIELDS ' do field extract
  Case "#3": ' do field extract
 End Select
End Sub

Sub LISTFIELDS
 i%=1: a1$=""
 Do While i%<40 And a1$<> "#"
   a1$=Field$(aa$,i%): Print i%;" ";a1$: i%=i%+1
 Loop
End Sub


> run
1 #1*
2 cc-rainy
3 Rain Likely
4 7.9
5 979.9
6 falling
7 95
8 6.0
9 SSE
10 null
11 11.0
12 null
13 6.0
14 6.24
15 1.74
16 Rain Likely
17 rainy
18 10.0
19 7.0
20 80
21 chance-rain
22 rain
23 Rain Possible
24 possibly-rainy-day
25 9.0
26 6.0
27 #
1 #2*
2 40
3 chance-rain
4 rain
5 Rain Likely
6 rainy
7 9.0
8 6.0
9 60
10 chance-rain
11 rain
12 Rain Likely
13 rainy
14 9.0
15 7.0
16 50
17 chance-rain
18 rain
19 2.75
20 3.24
21 conditions:Rain Likely
22 icon:rainy
23 precip_probability:95
24 precip_type:rain
25 feels_like:6.0
26 #

The UDP commands I used from another pi were:

echo "#1*,cc-rainy,Rain Likely,7.9,979.9,falling,95,6.0,SSE,null,11.0,null,6.0,6.24,1.74,Rain Likely,rainy,10.0,7.0,80,chance-rain,rain,Rain Possible,possibly-rainy-day,9.0,6.0,#,"| nc -u -w 1 192.168.2.150 4997

and

echo "#2*,40,chance-rain,rain,Rain Likely,rainy,9.0,6.0,60,chance-rain,rain,Rain Likely,rainy,9.0,7.0,50,chance-rain,rain,2.75,3.24,"conditions":"Rain Likely","icon":"rainy","precip_probability":95,"precip_type":"rain","feels_like":6.0,#,"| nc -u -w 1 192.168.2.150 4997

~
Edited 2020-12-14 01:05 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 04:52pm 13 Dec 2020
Copy link to clipboard 
Print this post

Yup still the same
It could be the version of Pi-Cromite I'm using which if it is is worse than frustrating because it's the only version that does triangle rotate
This is the result after using your code exactly as you wrote it.
I saw stuff fly up the screen but it won't let me scroll up.

I tried it 3 times and it always prints the exact same thing



I just added  print aa$, "here" at the end of Sub DECODE
and it prints this when the code runs


Edited 2020-12-14 03:45 by lew247
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3476
Posted: 05:59pm 13 Dec 2020
Copy link to clipboard 
Print this post

Output looks correct for #2, #1 doesn't end with "#,", #2 doesn't have "," at the end; likewise #3.

I didn't code for #3--to include it, put "LISTFIELDS" after Case "#3":

I'm not seeing that it isn't working. Which particular fields do you want, numbered relative to which UDP message they are in? (Maybe give meaningful variable names.)

Please post the text for UDP message #3 so I can cut and paste.

~
Edited 2020-12-14 04:03 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:51pm 13 Dec 2020
Copy link to clipboard 
Print this post

Sent you a message Lance rather than me annoying everyone
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3476
Posted: 08:37pm 13 Dec 2020
Copy link to clipboard 
Print this post

For ease of computation I changed the numbered variables, A1$-a50$ to an array: DIM a$(60).

This seems to me to work.

Option EXPLICIT
Dim ss$,sec1$,aa$,a1$,a2$,a43$,a50$,b$,c%, sec, tag$, i%
Dim  a$(60)
On error skip
UDP close
UDP server 4997
Do
 On error skip
 UDP receive aa$,b$,c%
 If c%>0 Then DECODE
Loop
UDP close

Sub DECODE
 tag$=Mid$(aa$,1,2)
 Select Case tag$
  Case "#1": For i%=1 To 25: a$(i%)=Field$(aa$,i%+1): Next i% ' LISTFIELDS
  Case "#2": For i%=1 To 25: a$(i%+25)=Field$(aa$,i%+1): Next i%
    For i%=1 To 50: Print i%;" ";a$(i%): Next i%
 End Select
End Sub


1 cc-rainy
2 Rain Likely
3 7.9
4 979.9
5 falling
6 95
7 6.0
8 SSE
9 null
10 11.0
11 null
12 6.0
13 6.24
14 1.74
15 Rain Likely
16 rainy
17 10.0
18 7.0
19 80
20 chance-rain
21 rain
22 Rain Possible
23 possibly-rainy-day
24 9.0
25 6.0
26 40
27 chance-rain
28 rain
29 Rain Likely
30 rainy
31 9.0
32 6.0
33 60
34 chance-rain
35 rain
36 Rain Likely
37 rainy
38 9.0
39 7.0
40 50
41 chance-rain
42 rain
43 2.75
44 3.24
45 conditions:Rain Likely
46 icon:rainy
47 precip_probability:95
48 precip_type:rain
49 feels_like:6.0
50 #


Same two netcat UDP messages as last posted.

Remember not to omit the "#," from the end of the UDP messages you construct on the ESP32, and the #1, #2 at the beginning.


~
Edited 2020-12-14 06:43 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 2 of 2    
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025