Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:55 02 Aug 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 : Webmite: UDP question

Author Message
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 07:59pm 30 Jun 2025
Copy link to clipboard 
Print this post

Hopefully someone out there can confirm a few things for me while I am away from all my Mites!

I was recently successful in being able to get two Webmites talking to each other (via UDP) by following the example in the PicoMite User Manual. By doing so, the mites were simply getting DHCP issued IP addresses.

A quick search on TBS revealed that static IP addresses could be assigned and this would be much better for my intended use case. So, on further investigation I found that in the manual it states that you can also set a 'name' by using:

OPTION WIFI ssid$, passwd$,[name$] [,ipaddress$, mask$,gateway$]

The questions I have are relating to the 'name$' parameter.

1: Is it possible to 'interrogate' what the name is (if set) on the local Webmite by using something like: print mm.info$(name)

2: can the command:
  WEB UDP SEND addr$, port, data$
(used on the other webmite) make reference to the name$ parameter of the Webmite you wish to talk to?
I ask, because the manual states "In this case the IP address must
be specified and can be either a numeric address (eg, "192.168.1.147") or a
normal text address (eg, "google.com")

3: are there any other uses (on either Webmite) where the name$ parameter is used?


Really would appreciate anyones feedback with the above - I will not be back with my Mites for another 48hours or so, hence I am unable to play or explore......
 
grumpyoldgeek
Newbie

Joined: 30/07/2018
Location: United States
Posts: 36
Posted: 03:28am 01 Jul 2025
Copy link to clipboard 
Print this post

Just a quick observation, it works better long term to have your router's dhcp server to reserve an IP address for your device rather than using a static IP.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:08am 01 Jul 2025
Copy link to clipboard 
Print this post

  Quote  Just a quick observation, it works better long term to have your router's dhcp server to reserve an IP address for your device rather than using a static IP.


Many thanks for your response. If I understand this correctly; currently my router has a reserve pool of addresses that it doesn't use for DHCP. Each Webmite will hence be set to a static IP within the appropriate range that is not used by DHCP.

My ideal scenario is for the 'master' webmite to be able to scan any 'slave' webmites on the LAN network and list their IP address and preferably list the name$ too.

This is all part of a crazy idea I have for a magazine article - a new 'TermMite' that has some rather nice features..........
Edited 2025-07-01 15:09 by WhiteWizzard
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 05:45am 01 Jul 2025
Copy link to clipboard 
Print this post

Most routers have the ability to configure a device with the same IP whenever it connects via DHCP.
This has the advantage that if you change routers and end up on a different IP range, the devices will get a valid IP instead of being lost in the wilderness.
This is my preferred way of doing things.

I haven't tried to use the pico name for connecting but when I added a pico to my host file, I could connect to it using the name for telnet and ping etc.

If you are setting up fixed IPs, just give the master pico a text file with the list of slave addresses and names. If you call it a hosts file, you will be doing things like the big boys.

Jim
VK7JH
MMedit
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2944
Posted: 05:53am 01 Jul 2025
Copy link to clipboard 
Print this post

Hi Jim,

Thanks (and great to hear from you!).

Makes sense regarding 'not getting lost in the wilderness' (should routers be changed); however, this is exactly the reason I want to be able to 'scan' the network as the 'list of slave addresses' stored at the master would then be incorrect. This wouldn't be a problem however IF the master could use the slave's name$ parameter in the UDP SEND command.

Really wish I had access to a couple of PicoW's right now...
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 08:03am 01 Jul 2025
Copy link to clipboard 
Print this post

Computers talk to a DNS server to convert the name into an address.
The hosts file on a Windows PC is checked first and if an entry is found, that is used. If not found, the PC asks the DNS server.
If your router can be configured to work as a local name server, that is one way. If not, you have to provide a DNS server because the internal device names will never get into a WWW DNS.
Even if your pico knows the name of it's friends, there has to be a DNS to convert it to IP numbers.

My main router could be interrogated to give me the names/IPs but it requires security that the pico won't do.

My other router can be configured to serve the name data but I am not going to mess with it.

Hope you aren't melting over there. Down to zero again tonight here!

Jim
VK7JH
MMedit
 
adcockm
Newbie

Joined: 03/05/2025
Location: United States
Posts: 4
Posted: 09:07am 01 Jul 2025
Copy link to clipboard 
Print this post

There's another option for what you're trying to do, but I don't think it's supported in WebMite.

UDP allows for broadcast messages to all devices in a network, as mentioned here. So if your local network range was something like 192.168.2.xxx you could send a broadcast message to 192.168.2.255 on a certain port, and as long as your server was listening on that port (and the UDP packets didn't get lost, which they can, so probably best to have a few retries built in), then it would pick up the message the client had broadcast out to the ether. You'd probably want to do a little handshake thing at that point, where the server sent a message back to the client, and they exchanged names, addresses, or whatever makes sense. Doing it this way means you really don't need to care about what network you're on, or how it's set up, as long as both the server and client(s) are on the same network, and the client can just use it's own IP address that it was given, and peel off the last number and replace it with 255 to broadcast.

I'm just not sure WebMite's UDP routines allow for sending a broadcast message like this, since it seems to require a specific option when the call is made, and I don't see anything like that mentioned in the manual. Kind of a shame, since that's one of the things that makes UDP useful. It's also fast, but there's no guarantee of transmission like there is with TCP (since the connection has to be made before you can send or receive data).
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3378
Posted: 02:08pm 01 Jul 2025
Copy link to clipboard 
Print this post

  grumpyoldgeek said  Just a quick observation, it works better long term to have your router's dhcp server to reserve an IP address for your device rather than using a static IP.


Not sure why this would be categorically true. I have used fixed IP addresses on various little IOT devices for 20+ years. I have replaced a router in this period--just make sure that you keep the same base IP range. If I replace a device, I just give it the same IP address (or a new one if there is a reason to).

~
Edited 2025-07-02 00:10 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
EDNEDN
Senior Member

Joined: 18/02/2023
Location: United States
Posts: 155
Posted: 09:00pm 13 Jul 2025
Copy link to clipboard 
Print this post

  lizby said  
  grumpyoldgeek said  Just a quick observation, it works better long term to have your router's dhcp server to reserve an IP address for your device rather than using a static IP.


Not sure why this would be categorically true.


It isn't so much the router's DHCP server is reserving an address.   It is more that it hands out the same IP address to a given MAC each time.    This is helpful in a variety of situations.    

For example, if you have bad power that blinks occasionally, your router might lose power but some of your computers with more beefy power supplies won't crash.   The router re-initializes, but your computers stay alive and think they still have a valid IP address.   So they never request a 'new' IP address.

If the router hands out the same IP address to any computer that requests one after the power blink you won't end up with IP address conflicts on the network.
 
aFox
Senior Member

Joined: 28/02/2023
Location: Germany
Posts: 105
Posted: 04:30pm 15 Jul 2025
Copy link to clipboard 
Print this post

  WhiteWizzard said  Hi Jim,

...

Really wish I had access to a couple of PicoW's right now...


Maybe give OliBasic's UDP commands on Android a try to enhance your device list.

https://www.tapatalk.com/groups/rfobasic/olibasic-3-0-preview-t6292-s50.html#p49851


UDP Socket Commands
User Datagram Protocol is a simpler message-based connectionless protocol. Connectionless protocols do not set up a dedicated end-to-end connection. Communication is achieved by transmitting information in one direction from source to destination without verifying the readiness or state of the receiver.

Unreliable – When an UDP message is sent, it cannot be known if it will reach its destination; it could get lost along the way. There is no concept of acknowledgment, retransmission, or timeout.
Not ordered – If two messages are sent to the same recipient, the order in which they arrive cannot be predicted.
Lightweight – There is no ordering of messages, no tracking connections, etc. It is a small transport layer designed on top of IP.
Datagrams – Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.
No congestion control – UDP itself does not avoid congestion. Congestion control measures must be implemented at the application level.
Broadcasts – being connectionless, UDP can broadcast - sent packets can be addressed to be receivable by all devices on the subnet.
Source: Wikipedia
Port range – from 32768 to 60999 is recommended.
A transfer request is always initiated targeting port 69, but the data transfer ports are chosen independently by the sender and receiver during the transfer initialization.
If you want a read and write communication (IoT), make sure that there is a pause of maybe 500ms for interaction.


UDP.read <result_svar>, <port_nexp>, <wait_nexp> {, <char_set_sexp>}
Listens for an UDP message on port <port_nexp> and read a string if any datagram message arrived.The command waits <wait_nexp> milliseconds. If <wait_nexp> is 0 it waits infinite. Using this command in a loop with 1200 ms for the first try is recommended. The character set can be specified by <char_set_sexp>. Use "_UTF-8" (default) for text and "_ISO-8859-1" for binary data. An input until 65527 bytes is accepted.

Example:
DO
 DO
   UDP.READ r$, 54321, 1200, "_ISO-8859-1"
 UNTIL r$ <> ""
 PRINT r$
UNTIL 0


UDP.write <message_svar>, <ip_adress_sexp>, <port_nexp> {, <char_set_sexp>}
Writes a string <message_svar> as an UDP datagram message to a local ip adress <ip_adress_sexp> on port <port_nexp>. The character set can be specified by <char_set_sexp>. Use "_UTF-8" (default) for text and "_ISO-8859-1" for binary data. An output until 65507 bytes is accepted.
But keep in mind that large messages will be splitted.

Example:
m$= "My message! "
FOR i = 1 TO 100
  mm$ = m$ + STR$(i)
  UDP.WRITE mm$, "192.168.1.12", 54321, "_ISO-8859-1"
  PAUSE 50
NEXT




Gregor
Edited 2025-07-16 02:33 by aFox
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 203
Posted: 10:10pm 15 Jul 2025
Copy link to clipboard 
Print this post

A note of caution about UDP from my own personal experience.

At a get-gether at his home, I was chatting with a manufacturing process engineer from the company we both worked for. He was talking about his new set of programmable logic controllers and how they communicated with them via UDP. I asked to see his home computer, and downloaded a UDP browser. I asked if he remembered any IP addresses for them, and we entered one. Up it came, visible through the company's well-maintained firewall.

He blanched, and made a phone call immediately.

The company's router was reconfigured within a few minutes, and we confirmed later that UDP would no longer get through the company firewall.

The lesson: Make sure your router / firewall lets through only the traffic you want, including UDP.
Live in the Future. It's Just Starting Now!
 
aFox
Senior Member

Joined: 28/02/2023
Location: Germany
Posts: 105
Posted: 02:41pm 17 Jul 2025
Copy link to clipboard 
Print this post

   
 
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