|
Forum Index : Microcontroller and PC projects : UDP
| Page 1 of 2 |
|||||
| Author | Message | ||||
| lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
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 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 KingdomPosts: 1702 |
original post edited |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10590 |
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: AustraliaPosts: 37 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3476 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3476 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3476 |
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 KingdomPosts: 1702 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3476 |
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 KingdomPosts: 1702 |
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 StatesPosts: 3476 |
"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 KingdomPosts: 1702 |
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 |
|||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |