Then I'm able to do something like:
socket.send('hi',3333,'192.168.1.1');
Interestingly enough, running send() FIRST seems to queue up the request. Upon running bind() later, the UDP packet gets sent.
I imagine that bind() must be running some sort of UDP initialization. I'm not sure if this is intentional or not but could explain why it seems difficult to send a UDP packet initially from Espruino.
For now, I'm okay with this workaround. I can just wrap a dummy bind() call in a initializeUdp() function.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
It looks like dgramSocket.send only works after running dgramSocket.bind.
I need to run the following first:
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
socket.bind(port, res => {});
Then I'm able to do something like:
socket.send('hi',3333,'192.168.1.1');
Interestingly enough, running send() FIRST seems to queue up the request. Upon running bind() later, the UDP packet gets sent.
I imagine that bind() must be running some sort of UDP initialization. I'm not sure if this is intentional or not but could explain why it seems difficult to send a UDP packet initially from Espruino.
For now, I'm okay with this workaround. I can just wrap a dummy bind() call in a initializeUdp() function.
Btw, I'm in 1v96 using a D1 mini pro.