Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Electroguard
#45133 cicciocb, I was trying to understand the port connections from your transmitter script, but the ip() function isn't working on my ESP Basic 2.0.Alpha 7.
print ip() returns 0.0.0.0, so I'm unable to construct a broadcast address from the dhcp address.

The modified UDP_controller still doesn't broadcast 'blind' msgs by the way, it pops up a window saying "A module from the ESP8266 list must be selected".
So I'm using a Processing script to send udp broadcasts for now.

It's all working very well though, I can broadcast commands to my ESP Basic udp framework and get appropriate responses back in the blink of an eye... you've done a great job there matey.

Because I can't run your transmitter script yet due to the ip() problem I mentioned, could you tell me what I would need to add (in a subroutine?) to a normally-listening receiver node for it to be able to also make a broadcast whenever required, then return to listening again?

Do I need to break the listening connection, then make the broadcast connection and transmit, then break the broadcast connection, and remake the listener connection again, (because they seem to be using the same port number) or is it easier than that?
User avatar
By cicciocb
#45153 Hi,
I checked the command ip() on my version and it returns the good IP of the module.
The problem, for me, is that I work all the time on a development version do I don't know if this is related to this particular version or your configuration; maybe someone else can report if this is the case.
Maybe the module is in WIFI access point ? If this is the case, I didn't tested in this condition at the modules are always connected to my home WIFI router.
If you want receive broadcast messages, you just need to enable the UDP server (command udpbegin 5001 in your code below). As soon as you receive a message, you have the choice to reply to the sender (command udpreply xxxx) or to send a broadcast message (command udpwrite xx.yy.zz.255, msg).
Take into account that writing to the broadcast address, you'll receive also locally the same message!
In this case you can use the command UdpRemote to know who sent the message and ignore it if is local.
If the ip() command don't works for you, you can use the UdpRemote to identify the sender and, by deduction, the network IP.
User avatar
By Electroguard
#45155 Good stuff, that helps a lot, thanks.
Yep, was in AP mode without connecting through router, but I'd still expect ip() to be returning the local 192.168.4.1 address even if it isn't a dhcp one. Doesn't stop progress though, so it's something for another day.
Not that it really matters anyway, cos running udp in AP mode is just a temporary artifical single node test environment until I can get some other nodes going also - so if ip() works on a dhcp node connected to a router, then I would think it should be possible to mask out any local broadcasted msgs to prevent nodes from talking to themselves (which is something I sometimes find myself doing!)
User avatar
By martinayotte
#45169 In plain SDK as well as Arduino framework, there are two different functions to return the IPAddr, one for STA and one for AP.
So the ESPBasic using only the STA function WiFi.localIP(), and not using the WiFi.softAPIP() function at all.