Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:28 16 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 1 of 2    
Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 04:41pm 06 May 2020
Copy link to clipboard 
Print this post

Has anyone got any ideas on how to intercept/monitor UDP traffic on the router?
My Weatherflow weather station sends data on
# udp_address = 0.0.0.0
# udp_address = 255.255.255.255
  udp_port = 50222

and the data it sends is

[[sensor_map]]
       outTemp = air_temperature.AR-00004444.obs_air
       outHumidity = relative_humidity.AR-00004444.obs_air
       pressure = station_pressure.AR-00004444.obs_air
       # lightning_strikes =  lightning_strike_count.AR-00004444.obs_air
       # avg_distance =  lightning_strike_avg_distance.AR-00004444.obs_air
       outTempBatteryStatus = battery.AR-00004444.obs_air
       windSpeed = wind_speed.SK-00001234.rapid_wind
       windDir = wind_direction.SK-00001234.rapid_wind
       # lux = illuminance.SK-00001234.obs_sky
       UV = uv.SK-00001234.obs_sky
       rain = rain_accumulated.SK-00001234.obs_sky
       windBatteryStatus = battery.SK-00001234.obs_sky
       radiation = solar_radiation.SK-00001234.obs_sky
# lightningYYY = distance.AR-00004444.evt_strike
# lightningZZZ = energy.AR-00004444.evt_strike

I'd like to "intercept" this data and use it for my weather display
Anyone got any ideas?

I've got a Pi-Cromite and also have an ESP8266 I could use with a different micromite

EDIT:
Reverted to the manual  
However I'm still stuck

The Pi-Cromite manual says
  Quote  
UDP SERVER nnnnnUDP Opens a UDP socket on the port nnnnn

UDP CLOSE  Closes an open UDP socket

UDP CLIENT server$, serverport, myport   Opens a socket as a client to a designated server. The server IP address is specified as a string of the form “192.168.1.149”. The serverport is the port number the intended server is expected to be listening on e.g. 123 for an ntp server. myport is the port the Pi-cromite will use to receive information from the serve

UDP SEND string$  Sends a string to a connected device via UDP.  When in client mode this will be the server specified in the UDP CLIENT statement. When in server mode this command can only be used after receiving an incoming message from a client as this will determine the address to use for SEND. An error will be reported if SEND is used in server mode before the link is established.

UDP RECEIVE string$ [,sender$] [,senderport%] Attempts to receive a message on an opened socket. If no message is waiting string$ and sender$  will be blank strings and senderport will be zero. If a messageis waiting it will be returned in string$. If sender$ is included in the command this will contain the IP address of the sender as a string e.g.”192.168.1.149”. if senderport% is specified it will contain the port number on which the sender would expect any reply. The senders IP address and port are automatically stored within the Pi-cromite and are used for any subsequent UDP SEND command


I'm "guessing" I need to do something like
UDP SERVER 50222
UDP RECEIVE string$
?
Not sure how exactly to do it though
anyone got any ideas how to use the command properly? ie examples?
Edited 2020-05-07 04:31 by lew247
 
lew247

Guru

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

original post edited
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10590
Posted: 06:52pm 06 May 2020
Copy link to clipboard 
Print this post

Its ages since I did anything with this so my memory is fuzzy. I think you should be opening as a client as the weather station is the server
 
yobortsa
Newbie

Joined: 12/12/2011
Location: Australia
Posts: 37
Posted: 10:29pm 08 May 2020
Copy link to clipboard 
Print this post

Does the Pi-cromite still run the standard RPi Operating System?

If so, make sure you are getting the data through. Netcat on Linux can be used for testing but it might not be installed as standard with your RPi distribution.

https://linux.die.net/man/1/nc

Listen on UDP port 50222 for incoming packets and display incoming data:

netcat -ul -p 50222


If you don't have netcat on RPi, search using Apt:

https://www.raspberrypi.org/documentation/linux/software/apt.md

If you receive UDP packets ok perhaps create a program to process the data on the RPi side, eg:

https://www.binarytides.com/programming-udp-sockets-c-linux/

-or-

https://pythontic.com/modules/socket/udp-client-server-example

I'm not sure about ethernet support for the Pi-cromite - I haven't used one.

Regards,

David
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 06:39am 09 May 2020
Copy link to clipboard 
Print this post

This is the code I used to get the UDP packets
DIM a$,b$,c%
on error skip
udp server 50222
do
 pause 500
 on error skip
 UDP receive a$,b$,c%
 if c%>0 then
   print a$
 end if
loop
on error skip
udp close


If anyone can help with parsing the packets, please see my other post titled parsing
 
lew247

Guru

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

Does anyone know how to get this to store before sending it to the aa$?
At the moment it doesn't seem to be storing it before going to the sub decode
The last field is always a *
it seems to be printimg 3 times
DIM aa1$,b$,c%
on error skip
udp server 4997
do
on error skip
UDP receive aa$,b$,c%
if c%>0 then
  DECODE
end if
ss$=mid$(time$,7,2): IF ss$ <> sec1$ THEN: sec1$ = ss$: print time$ : ENDIF
loop
on error skip
udp close

SUB DECODE
a1$ = FIELD$(aa$,1)
a2$ = FIELD$(aa$,2)
a43$ = FIELD$(aa$,43)
a50$ = FIELD$(aa$,50)
print a1$, a10$, a43$, a50$
print "Fin"
END SUB


This is the output

Edited 2020-12-13 04:08 by lew247
 
lizby
Guru

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

Storing what where?

a10$ doesn't seem to be defined. OPTION EXPLICIT may help.

What do you expect to receive in aa$? Where are b$, c$ defined (sender ip and port)?
Edited 2020-12-13 04:34 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

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

  lizby said  Storing what where?
a10$ doesn't seem to be defined. OPTION EXPLICIT may help.
What do you expect to receive in aa$? Where are b$, c$ defined (sender ip and port)?

I didn't have option explicit because it's just a "simple" test program to make sure another will work
It's receiving from an ESP32 and I'm sending it to this machines IP address
It's definitely getting the complete string that's sent because if I do print "aa$"
it shows me the complete string I've sent from the ESP
I did have an error which I've now corrected but it's still doing the same
going to SUB DECODE before the full string is received
I thought it would not go to SUB DECODE until the complete string was received
I put the "*" in field 50 so I can see it's decoding properly as the "*" will always be in that position

OPTION EXPLICIT
DIM ss$,sec1$,aa$,a1$,a2$,a43$,a50$,b$,c%, sec
udp server 4997
do
on error skip
UDP receive aa$,b$,c%
if c%>0 then
  DECODE
end if
ss$=mid$(time$,7,2): IF ss$ <> sec1$ THEN: sec1$ = ss$: print time$ : ENDIF  ' So I can see it's running
loop
udp close

SUB DECODE
a1$ = FIELD$(aa$,1)
a2$ = FIELD$(aa$,2)
a43$ = FIELD$(aa$,43)
a50$ = FIELD$(aa$,50)
print a1$, a2$, a43$, a50$
print "aa$"
END SUB


This is what's printed

 
lizby
Guru

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

Why not put a brief pause after UDP receive? Experimentation might determine how long a pause is needed.

Or rather, a pause before DECODE.

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

Guru

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

Thanks, I'll try that
I was trying to get it to go to the sub after it received the * but it wont
 
lew247

Guru

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

Nope neither pauses in the UDP receive and Decode sub make any difference
I did hope to try something like IF LOC(#1) = "8" then decode
but it doesn't work as its UDP
Edited 2020-12-13 05:28 by lew247
 
lew247

Guru

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

I'm such an idiot
I was sending # at the end and not *
using INSTR it works
 
lew247

Guru

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

Nope I'm still wrong

If I print aa$ it returns 441 characters
I think that might be the issue as I seem to remember something about 256 character limit
I tried using longstring append but can't figure out how to get it to work with UDP
when all I have is  UDP receive aa$,bb$,c% and it won't let me append to aa$
It won't accept aa() instead of aa$  
so frustrating
 
lizby
Guru

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

Can you have it sent with 2 UDP messages?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

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

Yes sorry I forgot to mention that
I had to send 3 udp messages as it wouldn't all fit in one
that's why I was trying to use append
it's sending all 3 messages
but I've no way of joining them together and one is overwriting the other
Edited 2020-12-13 07:04 by lew247
 
lew247

Guru

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

I really don't understand this
If I print aa$ it returns this
> run "e"
*,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,cha
nce-rain,rain,
11.0
Rain 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","prec
ip_probability":5,"precip_type":"rain","feels_like":5.0,#

but if I
print aa$
print a2$
it returns this
> run "e"
*,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,cha
nce-rain,rain,
11.0
Rain 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","prec
ip_probability":5,"precip_type":"rain","feels_like":5.0,#
8.0
>

This is obviously wrong because as You can see a3$ is Cloudy
and I'm using a3$ = FIELD$(aa$,3)

It seems if I try and do anything other than print aa$   aa$ corrupts
 
lizby
Guru

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

If each is less than 256 characters and there's enough time between them, why couldn't you LONGSTRING APPEND them?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

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

  lizby said  If each is less than 256 characters and there's enough time between them, why couldn't you LONGSTRING APPEND them?

I tried that but the manual says you have to use () for append and not $
I can set any delay between the UDP send because it comes from an ESP beside the MM
I guess I could connect them together using com ports direct or via HC-12 but I'd rather they were seperate which is why I'm hoping to get UDP cracked
 
lizby
Guru

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

"Couldy" would be correct if the third field was extracted from the string beginning with "*,cc-cloudy,Cloudy,6.3,993.0,rising,93,1.0,SW,null,1.0,null,5.0,1.74,1.59," (etc.)
But "8.0" is correct for the string beginning "Rain Possible,possibly-rainy-day,8.0,6.0,40,chance-rain,rain,Rain Likely,rainy,9" etc.

How do you determine which of the UDP strings you are working on when you try to extract the third field?

When you send the strings, can you tag them with something like "#1...", "#2, #3 and then do something like

tag$=mid$(aa$,1,2)
select case tag$
 case "#1": ' do field extract
 case "#2": ' do field extract
 case "#3": ' do field extract
end select
Edited 2020-12-13 08:18 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lew247

Guru

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

Nope
I've tried literally everything I can think of

I've made the ESp32 send
*string1#
#string2#
so it's easy to identify the start and end of each string
but nothing works
If there was only one UDP string and it was shorter then it would be fine because I can get that working perfectly
There's no way to tell the received UDP string to do 2 different things, I've tried case select, field$, if/then but none of it works properly
I think I'm going to have to use serial instead
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025