EspruinoWifi - UDP Broadcast ?

Posted on
  • Hi There

    Is it possible to broadcast with the EspruinoWifi ?

    A simple example sending / receiving would be nice.

    Sacha

  • It's not built-in yet, but I merged some code into Espruino's source code to add native UDP support just a few days ago. The hope is to get the Espruino WiFi specific code added for the 1v95 release.

    Having said that, you can still send AT commands directly to send the data you want. Just tried this and it works for me:

    function sendUDP(addr,port,data,callback) {
      if (!callback) callback=function(){};
      data = E.toString(data);
      var at = wifi.at;
      at.cmd('AT+CIPSTART=4,"UDP","'+addr+'",'­+port+','+port+',2\r\n',2000,function cb(d) {
        if (d=="4,CONNECT") return cb;
        if (d!="OK") return callback("ERROR: "+d);
        at.cmd('AT+CIPSEND=4,'+data.length+'\r\n­', 1000, function cb(d) {
          if (d=="OK") {
            at.register('> ', function() {
               at.unregister('> ');
               at.write(data);
               return "";
            });
            return cb;
          } else if (d=="Recv "+data.length+" bytes") {
            // all good, we expect this 
            return cb;
          } else if (d=="SEND OK") {
            at.cmd("AT+CIPCLOSE=4\r\n",1000,function­(d) {
              callback(d=="OK"?null:"ERROR: "+d);
            });        
          } else {
            callback("ERROR: "+d);
          }
        });
      });
    }
    
    sendUDP("255.255.255.255",4567,"Hello World\r\n")
    
  • Receiving is more of a pain - and honestly I think you're better off waiting for it to get implemented natively.

  • Thanks Gordon
    I will wait until 1.95 in the hope it will include udp support.
    Thanks
    Sacha

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

EspruinoWifi - UDP Broadcast ?

Posted by Avatar for Sacha @Sacha

Actions