-
• #27
Oh well.. url.parse is directly supported by espruino. I hacked away in and IDE with nodejs settings
and must have required the url module because something wasn't resolving. I am of to work now
but after i will test the changes as far as i can get.Do you have an github account? Would make things a lot easier to share code and collaborate in this project :)
-
• #28
yep, github, user (vaxus1).
-
• #29
Hi there,
I am also interested to integrate Alexa with Esp8266. I have an Echo Dot and esp8266 12E and I tried all the attached code with latest Espruino firmware downloaded from github master tree on tip.
I am getting lots of error when I am running discovery. doPost_handle* method is giving Javascript error.
I can also post the screen shot of error.
Another thing that I want to try the Alexa.js by PaddeK as a module but I don’t know how to call/use that module.
I am a Dot net programmer and new to nodeJs
Thanks -
• #30
paddek's version is still not working lets wait, his code is very sexy looking :) .
for esp u have to change some pin definitions. send the err log, interesting.
-
• #31
@Vasily its practically your code just refactored a bit.
According to Amazon my Echo Dot will ship on thursday.
I try to test and fix the things i messed up while blindly recfactoring
but without a actual alexa device on hand it will be hard.
I will make a repository for this on my github account and add you as a collaborator.
If this is not okay for you let me know and we will find a solution. I simply like to develop with
a VCS because i work on multiple machines. -
• #32
perfect plan... i was waiting a month to get espruino Udp working, so i wll be happy to see better code and working
-
• #33
I am in the midst of testing and was about to move the wifi part as external dependency (because there are at least two version EspruinoWifi/ESP8266WiFi) when i realized something odd.
You require a "Wifi" module which isn't known and you are not using a callback for the "getIP" method which is required in EspruinoWifi/ESP8266WiFi. Do you use a custom implementation for wifi?Edit
I am using latest travis build from here
Edit 2
Okay.. i should go to bed.. the espruino docs clearly say there is a Wifi module and its currently for ESP8266 only :)
Edit 3
Ok.. now i am hitting a real snag.. UDP support. I only have a EspruinoWifi and dgram is only
for ESP8266/ESP32 for now as far as i know. So i will have to wait for 1v95.
I pushed everything to https://github.com/PaddeK/espruino-alexa maybe you can test it beyond this point. -
• #34
@PaddeK! you can use echoshim.io for testing purpose. Just install Alexa App in your smart phone and connect it with Amazon account.
Echoshim is a browser based Echo emulator that is also connected with the same Amazon account that your actual echo dot.
-
• #35
@Vasily,
Till the time @PaddeK receives his Echo Dot, I will test the code on my dot.
So here are the details of error that I was talking about.Firmware flashed : From here "espruino_1v94_esp8266_4mb.tgz"
Test 1: I first tried file with name "alexa_ok4done.js" from your attachment.
Got a warning popup - Module dgram not found. But compiles without any issue. Result: Error in device discovery. So I fixed the code
msg += "USN: uuid:Socket-1_0-"+getSerialNumber()+"::urn:Belkin:device:**\r\n";
Test 2: I have modified the code and now device is discovered. But when I tried to turn it on/off using Alexa app.
onPageRequest ****************************************************** Header Req ( POST req.url= /upnp/control/basicevent1 Req= httpSRs { } Post length= Post url= { "method": "GET", "host": "", "path": "/upnp/control/basicevent1", "pathname": "/upnp/control/basicevent1", "search": null, "port": null, "query": null } ****************************************************** Post (/upnp/control/basicevent1) received, start special handling doPost_handleUpnpControl pdata.length == length67 / 299 pdata.length == length299 / 299 ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. at line 340 col 31 pinf("pdata == " + pdata); ^ in function called from system New interpreter error: CALLBACK,MEMORY onPageRequest ****************************************************** Header Req ( POST req.url= /upnp/control/basicevent1 Req= httpSRs { } Post length= Post url= { "method": "GET", "host": "", "path": "/upnp/control/basicevent1", "pathname": "/upnp/control/basicevent1", "search": null, "port": null, "query": null } ****************************************************** Post (/upnp/control/basicevent1) received, start special handling doPost_handleUpnpControl Uncaught SyntaxError: Got return expected '}' at line 415 col 4 }); ^ in function "doPost_handleUpnpControl" called from line 170 col 41 doPost_handleUpnpControl(req,res); ^ at line 171 col 9 break; ^ in function called from system server.on UDP message received ---
And via Alexa Ask
onPageRequest ****************************************************** Header Req ( POST req.url= /upnp/control/basicevent1 Req= httpSRs { } Post length= Post url= { "method": "GET", "host": "", "path": "/upnp/control/basicevent1", "pathname": "/upnp/control/basicevent1", "search": null, "port": null, "query": null } ****************************************************** Post (/upnp/control/basicevent1) received, start special handling doPost_handleUpnpControl pdata.length == length366 / 299 ERROR: Error processing Serial data handler - removing it. Execution Interrupted during event processing. at line 336 col 66 ...ata.length + " / " + length);
I will try @PaddeK module share the results.
EDIT: Just tried the Alexa module. It is not working. I gave saved the alexa.js in my local disk in SandBox folder. My other modules are loaded from the same location, so seems there is no issue with loading of the module from disk._____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://espruino.com 1v94 Copyright 2017 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 4MB:512/512, manuf 0xe0 chip 0x4016 >Uncaught SyntaxError: Got UNFINISHED STRING expected EOF at line 1 col 27 Modules.addCached("alexa","'use strict';\n\nconst\n Defau... ^ New interpreter error: LOW_MEMORY,MEMORY Uncaught Error: Module "alexa" not found at line 1 col 28 var alexa = require('alexa'); ^ =undefined
1 Attachment
-
• #36
Thx @Abhinav for the hint to echoshim.io this will be perfect for testing.
But i have to get UDP working first on my EspruinoWifi.
For testing the current version of the alexa module try this:let Wifi = require('Wifi'), Alexa = require('https://raw.githubusercontent.com/PaddeK/espruino-alexa/master/alexa.js'); let alexa = new Alexa(Wifi, { wifi: { ssid: 'your-wifi-ssid', password: 'your-wifi-password' } });
The used Wifi module is a copy of the EspruinoWifi with some fixes i added. If you have a ESP board you should be fine.. if you use EspruinoWifi you will get an error in getIP without the fixed
version. -
• #37
You can compile the Linux version of espruino and use that for testing.
-
• #38
@PaddeK yes, sorry about this. UDP support for Espruino WiFi is something I am working on - but it still needs a bit more work before it's usable.
The
getIP
on ESP8266 is a source of continual frustration for me (much like the baud rate). I really wanted an API that worked the same across all platforms,getIP
returns the value on ESP8266 because it can, so most people use that and then the code isn't portable :( -
• #39
getip works fine on esp only after you request wifi connection. regardless it got connected or not.
-
• #40
I changed getIP occurrences already to the callback variation.. but in the EspruinoWifi module is a bug that prevented me to use getIP without beeing connected to just get the mac address. That is the fix i was talking about and i will make a pull request when i have looked more into possible side effects of my fix.
@Gordon Do you have a rough timeline when UDP support is done? Or would it be worth it to hack the few things i need for this together myself.. if at all feasible.
-
• #41
Actually GetIP() is used to get just a device-id. It you can thing about any other "id", lets use it instead.
V.
-
• #42
@PaddeK ahh, ok. Thanks - I look forward to a PR when it's ready. It could potentially be difficult since the ESP8266 should be powered off when not connected.
As a hack for sending UDP, you can do something like this for now:
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); } }); }); }
But I have attached my extremely work in progress UDP implementation.
It may be that this just isn't possible with the ESP8266 AT firmware. As far as I can tell the AT firmware provides no information on where a UDP packet came from (address/port), so it might not be possible to send a response back to the right address (unless you know for sure where Alexa is).
1 Attachment
-
• #43
@Gordon thanks for the code.. had no time so far to look into it though.
@Vasily i saw that the getIP call is for getting the mac address and that it is only used to create an identifier.. but i think its a good idea so i left it in.Only problem right now.. besides spare time to get into it.. is UDP or more specific multicast UDP.
In a short research i found inconsistent statements about support of the AT firmware for multicast UDP. I guess next step will be to whip up some dirty test code and see if alexa can find a device.By the way there is a chance the rest of the code works as is.. at least for folks with a ESP8266.
-
• #44
Why not use the inbuilt getserial() to use as the ide as they will be portable.
-
• #45
whatever bug in UDP implementation you found, it works for alexa device discovery at the moment :)
so... never touch a working system is a prophecy -
• #46
@Wilberforce i think using the mac address is a better fit in this scenario and there are multiple ways to get a mac address then a serial. But to be portable i used the callback variation of getIP so we should be fine in this regard.
@Vasily nice to hear!! And to be clear... there is no bug in UDP its just not know supported for espruino devices.. so the alexa code right now just works for ESP8266 and maybe ESP32 users.
-
• #47
So i am back on this and i was surprised that with v1.95 i had to require Wifi instead of EspruinoWifi and no more errors because of missing Dgram module. But it still does not work for me.. its seems i cant receive alexas UPnP requests.
@Vasily Does this still work for you after updating to v1.95?
Edit
Okay.. after checking v1.95 change nodes, reading the updated references and making some changes i am few steps closer and could fix some bugs in code i never reached before.
Now i am stuck at an error from espruino "CIPSERVER failed" .. i guess it is the Dgram.createSocket but i have to check that after some sleep and try to reduce it a minimal snippet to reproduce.
Other odd thing.. Wifi.startAP seems to always want a password.. even with authMode "open". For now i did remove the AP parts.. don't know why they are needed anyways.. maybe you could shed some light on this @Vasily? :)
-
• #49
it's a miracle... I thought 15 mins ago... long time no answers on Espruino, and here you are, both :-)
I did not make any updates or trials, while my code was working on 1.94 and I was happy with it.
I am rather waiting your OO version that works.p.s. I will try upgrade to 1.95 and check if my script works same. Also I will consider comments from Gordon on right modules.
you found me online, wanted to try....
the lines with require('dgram') and other highligted red - err.
but compiled and uploaded anyway.... than an execution error came:
I would say I better wait you get your Alexa :-)