• The conversation is moved from here http://forum.espruino.com/conversations/­293517/

    I know how to integrate Espruino with Amazon Alexa (using existent Belkin smart-device protocol). It will be a huge advance for Espruino as a common smart-device platform.

    For that main part is UDP support because Alexa is making "device discovering" by sending UDP package and waint UDP answer with device specific details.

    Espruino latest builds have UDP support built in.
    To test it there are 3 scripts impelemented.
    https://github.com/espruino/Espruino/blo­b/master/tests/test_dgram_socket.js
    https://github.com/espruino/Espruino/blo­b/master/tests/test_dgram_multi.js
    https://github.com/espruino/Espruino/blo­b/master/tests/test_dgram_reuseAddr.js

    I've finally tried the master build today. Unfortunatelly it does not work when Espruino flashed directly on ESP8266 board.
    Notes: I m sure using correct cutting edge build http://www.espruino.com/binaries/travis/­master/.
    Because when used the official v1.94, the command "require('dgram')" was just failing, now it works.

    I tried 3 tests and nothing worked. Please help with traicing the cause.

    *** 1. test_dgram_reuseAddr.js - error returned
    Flash map 4MB:512/512, manuf 0xc8 chip 0x4014

    Uncaught InternalError: Unable to create socket
    at line 1 col 15
    srv2.bind(port);
    =undefined

    *** 2. test_dgram_socket.js - nothing returned (expected msg on send and receive)
    Flash map 4MB:512/512, manuf 0xc8 chip 0x4014

    =undefined
    server disconnected
    client disconnected

    Notes: I ve tested some extra msg-logs and removed srv.close and client.close.... IMHO, still seams that network.c fails and returns into networkGetFromVarIfOnline();

    *** 3. test_dgram_multi.js - nothing returned (expected msg on send and receive)
    Flash map 4MB:512/512, manuf 0xc8 chip 0x4014

    =undefined
    server 1 disconnected
    server 2 disconnected
    =undefined

    Notes: also very strange that msg "server 1/2 disconnected" received but msg "client disconnected" is not received

    p.s. I've tried to get connected to wifi at first, changed client.send(.... IP) to 127.0.0.1 and also to the wifi real IP after ESP is connected. Nothing changed. Would love to debug but do not know how.

  • Hi!

    Could you post the whole code and step by step process you followed? The tests are not ready-to-use scripts to use on the boards. One needs to wait for the network to connect etc...

    Perhaps you can test the captive portal script available at https://github.com/espruino/Espruino/iss­ues/1221. That one seems to be ready to be sent from the IDE and should give you an access point which renders a web page when connected to from a phone.

    Best Regards
    Standa

  • Hi @opi / Standa.

    I checked the code of CaptivePortal now, looks simple. Is is really working already? I mean does it receive the incoming DNS messages? This is the corner stone that I cannt succeed so far.

    For my tests I used test_dgram_socket.js AS-IS without modifications - it did not work.
    Than I added at the top of the script just few lines that connect to my local Wifi, nothing else. Unfortunatelly it did not help either. Here are extra lines, after it starts I see new IP device on my network (I can also ping it)

    var wifi = require("Wifi");
    wifi.connect("my-ssid", {password:"my-pwd"}, function(err){
    console.log("connected? err=", err, "info=", wifi.getIP());
    });
    wifi.stopAP();

  • The CaptivePortal example should be functional.

    The connect call is asynchronous, so you would need to put the test code into the connect() callback function (right below the console.log()).

  • "should be" is not an option :-) Did you try it specifically on ESP?

    I do not see a difference from captiveportal vs test_dgram...., both use bind and server.on...

    Well I will give a try anyway....I will need to implement send-udp on my PC than.

  • Hey, I got progress and ALMOST DONE....

    PLEEEEESEEE HELP!!!! We'r very close to get Alexa integration

    The CaptivePortal script is working on my ESP. Looks good.
    When I rewrote test_dgram with server side UDP from CaptivePortal it was not working anyway... seams the script has client's part problem. Never mind.

    But my Alexa script WORKS to receive UDP requests now!!!! YUHUUUU!!!

    Small info how Alexa works:

    • Alexa sends UDP multicast request to discover devices
    • device answer UDP package identifyng itself as Belkin IoT and answer has a http link to on/off page

    In arduino I used folowing Alexa UDP broadcast params
    (it works, I use it myself long time now):
    IPAddress ipMulti(239, 255, 255, 250); // 239.x.x.x is for Belkin discoverable devices
    const unsigned int port = 1900;

    Now... I did implement Alexa protocol already, playing and search Espruino git around. I managed to get UDP incomings with addon param dgram.createSocket(...multicastGroup:

    I attach my script. Please put you SSID and PWD.

    Still Alexa is not recognizing response and answers "no new devices found".

    I need help!!! How to send correct UDP response? I saw CaptivePortal and it is pretty awkward. I am sure that the text msg I prepare is correct - need just reformat it in binary I guess.

    Thanks.


    1 Attachment

  • For multicast support you need to use socket.addMembership() method (The dgram module is mostly compatible with node.js' https://nodejs.org/api/dgram.html). There are node.js ssdp implementations available to have a look at.

    Here is an Espruino specific example of an mdns (multicast DNS) module I crafted.

  • Cool, I will try .... and I guess also socket.setMulticastInterface() can help.
    But currently UDP receiving is ok already. I need a help to make correct UDP sending.

    Thanks for the link https://nodejs.org/api/dgram.html, if it is fully implemented than by just using socket.send(msg, [offset, length,] port [, address] [, callback]) it should work.

    Can you give me in hand in that, PLEASE...?

    p.s. I did not go much in C code as I act already on .bin file with JS scripts only.

    Txs, Vasily.

  • I give up now at 3AM. Seams that sending UDP package does not work.
    I tried all possible ways I can immagine, also intalled SmartSniff to check on PC what are UDP package around. As well did a script that ESP will send simplest UDP package to my PC and not to Alexa. All tries are hopeless, nothing is sent (apparently).

    I tried to adapt CaptivePortal as it declared to be working. Still no success.

    Any help appresciated.

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

Testing UDP on ESP8266 - problems with newest 1.94+. Using UDP broadcast for Alexa integration

Posted by Avatar for Vasily @Vasily

Actions