-
• #2
You can upload them using the normal
Storage
button in the middle of the IDE screen and uploading the file from eg https://www.espruino.com/modules/MQTT.min.js to a file calledMQTT
I don't think the IDE is smart enough to know that the modules are actually installed on the device and to not re-upload them, but nothing stops you from renaming it
MyMQTT
on the device, and then doingrequire("MyMQTT");
-
• #3
Many thanks for your quick response. Yes the WebIDE will always reload the module. Small modules I manually store and add
S
to the stored name like in this case it will beMQTT-S
. Missed that feature of the WebIDE to upload modules to strorage, will definitl give it a try.Copy paste from browser to the WebIDE does not look nice.
1 Attachment
-
• #4
use
curl -O https://www.espruino.com/modules/MQTT.min.js
to download that module and use this code to upload to storage.s = require("Storage"); module=` <content of file MQTT.min.js> `; s.write("MQTT-S",module.replace(/[\n\r]/g, ''));
Now you can use it like this:
s = require("Storage"); mqtt = require("MQTT-S");
As this does not happen to often, I am fine with those manual steps ;-)
1 Attachment
-
• #5
Hmm, ist does not work with MQTT.min.js
>mqtt = require("MQTT-S") Uncaught SyntaxError: Got EOF expected '}' at line 1 col 3902 ....write(f(e.DISCONNECT<<4)+"")}catch(a){return this._scktClo... ^ >
-
• #6
ok, there are 3 line of code in MQTT.js that cause this.
line 234
this.client.write(fromCharCode(TYPE.PINGRESP << 4) + "\x00"); // change to this.client.write(fromCharCode(TYPE.PINGRESP << 4,0));
line 320
this.client.write(fromCharCode(TYPE.DISCONNECT << 4) + "\x00"); // change to this.client.write(fromCharCode(TYPE.DISCONNECT << 4, 0));
line 386
this.client.write(fromCharCode(TYPE.PINGREQ << 4) + "\x00"); // change to this.client.write(fromCharCode(TYPE.PINGREQ << 4,0));
Just created a pr for this and added a screenshot using it as
MQTTX-S
without errors.
1 Attachment
-
• #7
I merged that PR as the code looks like an improvement, but the original code isn't broken. Uploading by copy/pasting into a templated str is a pretty bad idea as if you have any escape characters in strings they need double-escaping like
"\\x00"
or they will cause problems(as you noticed!)Upload via the IDE menu is much safer
-
• #8
This is the way I try to use:
- load file into WebIDE ( see attached screenshots, ide complains )
- change upload destination to storage
- enter the new filename
- upload
Did the upload and got errors, guess I am missing something.
> >Uncaught ReferenceError: "exports" is not defined at line 1 col 6064 ...tocol_level+i+r,n)},exports.create=function(t,e){return new ... ^ > >
3 Attachments
- load file into WebIDE ( see attached screenshots, ide complains )
-
• #9
I think you've misunderstood - there is an actual button for uploads!
- Go to https://www.espruino.com/ide/
- Connect to your device
- Click the
Storage
icon (4 discs, basically in the middle of the screen) - Click
Upload Files
- Upload your file using the file chooser
Uploading your way will work but as you noted it's messy!
In your case, you can ignore the
"exports" is not defined
error. It's because after upload the IDE is trying to run your module as if it's a normal app - but it's a module. - Go to https://www.espruino.com/ide/
-
• #10
Wow, way to easy - many thanks for clarification!
Is this possible via command line too?
2 Attachments
-
• #11
Is this possible via command line too?
yes!
--storage fn:data.bin : Load 'data.bin' from disk and write it to Storage as 'fn'
I think that works - can't remember for sure now - it's possible it attempts to write using
Flash
though -
• #12
Yes, perfect. Many thanks for implementing all this super helpfull stuff.
espruino --port /dev/tty.usbserial-54240369371 -b 115200 --storage MQTTCL-S:MQTT.min.js ... > Upload Complete >require('Storage').list() =[ "MQTT-S", "MQTTCL-S" ] >mqtt = require('MQTTCL-S') ={ create: function (t,e) { ... }, connect: function (t) { ... } } >
Sometimes uploading is taking too long because you use larges modules like MQTT. Is there an easy way to save the loaded module to storage. So next time you uses
mqtt = require("MQTTS")
.