-
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. -
@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. -
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 :)
-
I took a first shot at it. Its more an exercise for me to get to know what is going on.
Sadly my Alexa is still on its way so i haven't tested anything of this yet and i would be surprised if it works out of the box.Next steps would be to heavily reduce debug messages, of course testing and then adding more features and so on.
-
-
-
Try minify yourself.. at least some parts.. first place i would start is console.log. You have quite a lot of them and multiple times in a row.
In your setupId function for example:
console.log("NAME: " + gFriendlyName); console.log("SERIAL: " + gSerialNumber); console.log("UUID: " + gUuid);
Try to combine this to a single console.log
console.log("NAME: " + gFriendlyName, "SERIAL: " + gSerialNumber, "UUID: " + gUuid);
I am not aware of a minifier that does this for you without breaking everything.
Using arrow functions could scrape another few bytes. I could take a stab at minifying this
later today.Edit
Offloading fixed strings etc. to a eeprom could help too.
-
-
Well it seems to me you are trying to parse a XML response with JSON.parse. You will need a XML parser to get what you want.
If you are just interested in the BinaryState Tag value you can get by with a regex if they are supported.
// Gives you the value of BinaryState let binaryState = /<BinaryState>(\d)<\/BinaryState>/.exec(pdata)[1];
-
@Gordon no i am not on patreon. I was under the impression this topic is a place to chime in with ideas. I was in no way complaining about power consumption of the current boards, but in my opinion hardwarewise there are just two directions to go.. more power (ram/cpu etc.) or less power consumption. The nordic nrf52840 promises both and if i am not mistaken will be easy to support. So as far as pro and cons lists go this should be a winner.
I will avoid this topic/subforum in the future. Sorry for the intrusion.
-
-
He could use LiFePO4 batteries.. they have a nominal voltage of 3.2/3.3 volts.. they are pretty much perfect for 3.3v projects. Here is a video about it https://www.youtube.com/watch?v=DicVZfW5YL0
. -
-
-
Thx @DrAzzy i think this could help me.. and i did see a version with mounting holes in your tindie store that i like even more. While researching easy solutions i came across this https://www.youtube.com/watch?v=Fau2naIkbNU
.. so awesome!-- Edit --
Just ordered some boards Thanks! :) -
I am in the near future in a similar situation (needing to address multiple spi, i2c and one uart device). If my research so far is correct sharing pins between protocols will not work.. maybe if your SPI devices and I2C devices can work at the same frequency.. but even then i am skeptic.
To my astonishment there seems to be no easy way to share pins with multiple devices for SPI.
I found a I2C hub from seeed studio which i will give a try.. but common solution seems to involve soldering, making your own cables or using a breadboard. Have you by any chance found a solution for this? -
With the new encoding it doesn't crash.. but it returns after quite some while.. about 15min+ with a wrong result. Thats odd :D
To not further spam this forum with huge encoded data i created
a gist https://gist.github.com/PaddeK/4c717e9c2a86a39efede7ac672c96f5b -
-
For my test input of 5310 chars it still crashes.
After quite a while i get this error message:Uncaught Error: Unknown escape character 117 in RegEx at line 1 col 184 ...{return a.charCodeAt(0)%10}) ^ in function "dec" called from line 2 col 229 ...)%10})};console.log(dec(img).length); ^ >
Here is the full example code to reproduce:
let img = '720/Ç66/D65/gf64/wB64/ÆAH63/+2Af63/g2A63/ÂÇAD63/PÄwP62/wPjg62/+Q/PD62/nDÆ+PÆ60/Æ+PÃÂ/j60/l2/vzÂP59/Æj/+/PAf59/kv/ÅÇwB59/Æw2/P¾AH59/lv/Æ/Bwf58/+C2/z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B2wMBxAY2EBxwID6AP5/+AfÆBAGAhg2GBAEAEAYQcCEAQgCAIYDA2gCADAQwDCAgDCDgQgDGBgE6A6/ÂD/wEAQCEAIQMAQAwBhB2YQBiAYAhgIDGAIAIBCAEIGAMILCGAMYEAI5AB6/gf/AMBAIQAhA2/gCA2CEhD/+GBADEAgMf/gAgEIAQgQAQxkIQARgf/g5AD5/+D/ÆAYEAhACED3AIA2Ij2M2AMEAMQCAxg2ACAQgBCBA2BERhABGB8AH5/Âf/wAYQCEAIQI3AgAgyE2g2AMQAxAIDE3AIBCAEIEA2EQkEAEYE8AP5/j2/2AhAIQAhAw2ADAGBQSB3ARACEAgMQ3AgEIAQgYAwKCQYAxgQ8Af7/ÆACEAhgGEBAEAEAYHAwEAQBCAIQCAwgCACAQwDCAgDAÂGAgDGBgE7Af7/wAIQCDAYQGAgAIDgMDAIDAEM2BAI2DAQAI2BgMIDAcBAYDAcYCAw7A8/AxhAI2GhA2M2AÂyAgMA2ÂYw2YEAgM2G2AgE2DQgHGQEBAHGRg2G8A7/ÆAÂEAgHiEAPg2A+I4A+AcAfAQC2AHwACAQDxCAHx4AHx2APg8A7/w59A7/60AP5/Æ987A'; let dec = t => t.replace(/(\d+)([^\d])/g, (m, r, c) => new Array(+r + 1).join(c)).replace(/[¾µÀÁÂÃÄÅÆÇ]/g, i => i.charCodeAt(0) % 10); console.log(dec(img).length);
-
It would need base64 as input for the encoding and the result of that is input for the decoding.
The encoding step basicly substitutes the numbers with some characters outside of the base64 alphabet and then does a runlength encoding. I never tried the encoding step in espruino though.To give a little background.. i recently got a eink display (waveshare 4.2 inch) and i wanted to display full size (400x300) images with espruino. The output of the common img2lcd tool was
to big because of all the overhead of hex notation, commas, spaces and line breaks. The image
information itself is just 15k bytes but in this representation its close to 80k bytes. So i base64 encoded the image which gives me 20k bytes which by the way runs just fine. But i saw major potential to further reduce the size with some RLE.Having any compression/decompression options build in would be nice and if the output of the compression could be an accepted string would be nice for assets.
-
-
Okay here are the results in respect of RLE.
First the two contenders:
Unminified
module.exports = { enc: string => { let map = (count, char) => (count > 1 ? count : '') + ('¾µÀÁÂÃÄÅÆÇ'[char] || char), counter = 0, last = ''; return [].reduce.call(string, (result, char, index) => { if (last !== char) { result += map(counter, last); counter = 0; last = char; } counter++; if (index >= string.length - 1) { result += map(counter, last); } return result; }, ''); }, dec: string => { let map = char =>'0123456789'['¾µÀÁÂÃÄÅÆÇ'.indexOf(char)] || char, count = ''; return [].reduce.call(string, (result, char) => { if (!isNaN(parseInt(char))) { count += char; return result; } else { result += count.length ? new Array(parseInt(count) + 1).join(map(char)) : map(char); count = ''; } return result; }, ''); } };
Minified
module.exports=((a,b)=>({enc:t=>b.call(t,(p,c,x)=>{return p.l!==c&&([p.r,p.c,p.l]=[p.r+p.f(p.c,p.l),0,c]),p.c++,x>=t.length-1&&(p.r+=p.f(p.c,p.l)),p},{l:'',r:'',c:0,f:(c,s)=>(c>1?c:'')+(a[s]||s)}).r,dec:t=>b.call(t,(p,c)=>{return[p.r,p.j]=[~~c==c?p.r:p.r+(p.j?Array(+p.j+1).join(p.m(c)):p.m(c)),~~c==c?p.j+c:''],p},{r:'',m:i=>'0123456789'[a.indexOf(i)]||i,j:''}).r}))('¾µÀÁÂÃÄÅÆÇ',[].reduce)
I minify by hand but i tested the code in the browser and nodejs and confirmed both versions work as expected. It is not a straight RLE implementation as you can see.. the purpose is to minify base64 strings, so there is some substitution going on.
In regard to espruino the unminfied version is running fine. The minified version however behaves unexpected. The webIDE freezes.. reconnecting to the board does not work, even typing on the left side is not working. Restarting the webIDE has no effect. I have to reflash my espruino wifi to fix this.
-- Edit --
I tested the latest cutting edge build (1v94.130) with thislet dec = t => t.replace(/(\d+)([^\d])/g, (m, r, c) => new Array(+r + 1).join(c)).replace(/[¾µÀÁÂÃÄÅÆÇ]/g, i => i.charCodeAt(0) % 10);
I get the same behaviour as with my minified non regex version.
-
Thanks @Gordon i will give it a try. I am in the process of deminifying my RLE implementation.
The lack of backreferences is negligible. I guess its a more advanced feature anyway.In my case i only need the backreferences for encoding.. which is a pre step on the PC. I only need the decoding part on the espruino.
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:
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.