-
-
Aha, that must be it!
I had misunderstood deep sleep and thought things would work like normal from the time it wakes up until it's done doing stuff. Classic example of RTFM :)
Espruino can't be woken by Serial/USART traffic (and will not receive data while in Deep Sleep). (…) To work around this, you'd need to implement RTS/CTS flow control in software (waking Espruino on RTS, and only setting CTS after setDeepSleep(0) has been called).
SIM7000 does support RTS/CTS hardware flow control, so I'll try that. Thank you!
Edit: The shield didn't though, so I ended up disabling/enabling it manually.
-
I've bought a shiny new SIM7000 GSM/LTE module that I've managed to get working with Espruino Pico.
My problem is that the USART interface stops working when I disconnect the Pico from the USB port and power it from a LiPo battery. I first used
Serial1
withUSB.setConsole(true)
, then triedSerial2
instead, without noticing any difference. The code runs fine, logging any errors to an array so I can check it later. But the USART connection goes quiet as soon as USB is disconnected – any AT commands sent to the module never get a response. If I connect it to the USB port again and use the Web IDE, everything is back to normal.What could be going on? Is there something obvious that I've missed when setting up USART?
I should mention that I've actually made my own version of the AT module, using promises instead of callbacks, plus a few other changes that I needed in order to get it to work with SIM7000 (and to understand what it was doing – really good programming excercise!). While the bug could lie somewhere in that code, it does work perfectly fine when connected to USB.
Relevant excerpts from my code (yes, no semicolons!):
const USART = Serial2 const BAUD = 115200 const PWRKEY = B4 const at = require('AT').setup(USART) // Enable the PWRKEY pin pinMode(PWRKEY, 'output') // Enable Espruino's deep sleep mode setDeepSleep(true) // Deal with any uncaught exceptions process.on('uncaughtException', logError) E.on('init', () => { USB.setConsole(true) USART.setup(BAUD) }) function test() { digitalPulse(PWRKEY, LOW, 100) // Power on // Listen for "SMS Ready" URC, time out after 10 seconds at.listen('SMS Ready', 10000) // similar to at.register() in the official module .then(…) // do stuff .catch(logError) // logs error to an array for later retrieval // When connected to USB, it receives "SMS Ready" 100% of the time // When connected to battery only, the SIM7000 module powers on but at.listen() times out with nothing being received // When connected back to USB again (without rebooting), AT commands are received }
I'm programming the Pico from the Web IDE using "Save on Send: Direct to Flash".
I've also tried putting
USB.setConsole(true)
at the very top of the code.Any help would be greatly appreciated!
-
No, not at all - I was only joking :)
Even still, I felt like an ungrateful kid begging for icecream after having been served a delicious cake :)
I actually have checked whether
for…of
was supported, but never thought of suggesting it here! Maybe it's been overlooked because iterators and loops are not as attractive as arrow keys and async/await.. -
Shouldn't be too hard to implement, should it? :)
Here you go https://github.com/espruino/Espruino :)
Now I regret saying that :) It came off wrong, sorry if it sounded like writing features for Espruino is easy! I'm sure it would take many hours to implement this, and I know you're not getting paid by the hour to work on Espruino. Instead I should thank you for making and continuously improving Espruino for free, and for providing such great support!
I looked around for JS polyfills for
Map
andSet
, and found one that was used by Firefox Nightly and Chrome Dev when the features were under the Enable Experimental JavaScript flag. It's also the smallest that I found (6KB, 2.77KB minified) and claims to have good performance.https://github.com/WebReflection/es6-collections
https://raw.githubusercontent.com/WebReflection/es6-collections/master/index.jsAs far as I can tell, it actually does roughly what your bodged up implementation does :)
I tested it on a Pico (had to move the exported functions to the bottom) and it seems to work fine, except for two issues:
- Although it shims iterators, Espruino doesn't support iterators or
for…of
(good point!) - The
.size
property is missing (requires support for getters inObject.defineProperty
)
https://gist.github.com/joakim/e70a8c1bb82b3cce32092cccfb99701d
Despite those issues, I'll give it a try on a project I'm working on later and see how it goes.
- Although it shims iterators, Espruino doesn't support iterators or
-
Oops, I merged a pull request too quickly.
I haven't released the latest changes on NPM though, so if you fetch the module using
npm install rollup-espruino
it should work (that is, use v0.2.1).. The updated example configuration in the README should be correct though, while the one in v0.2.1 may no longer work.I'll be working on this plugin soon, and will iron out any issues then. Hopefully in a few days!
-
Actually,
Map
is something I've missed several times lately when bothObject
andArray
have fallen short.Set
would also be useful. Having become used to the two in NodeJS, it's hard to live without them in Espruino :)Arguments for adding
Map
:
UntilMap
arrived, JavaScript lacked a "pure" associative array. Instead,Object
is often used/misused, leading to complicated code and weird issues, mainly due to its prototype nature and its limitation of only strings as keys.
WithMap
, keys can be of any type, they're easily iterated (in insertion order), and it's easy to get a map's size or check if it has a certain key. It performs better, and it just works! After years of trying to makeObject
behave like an associative array, it's like a breath of fresh air.Shouldn't be too hard to implement, should it? :)
-
I just had this issue in a 1v91 flashed puck (not the Uncaught Syntax error, but disconnections on
save()
andE.setBootCode()
). I canreset()
just fine, but it still crashes onsave()
. Can't remember what exactly I did to trigger this, but I was messing withNRF
and listening for button presses to sleep/wake BLE. And I did have "save on send" enabled by accident. I also did a lot of hardware reset,reset()
,save()
andE.setBootCode()
(roughly in that order) to try to fix things, but apparently I broke things even more :/The peek functions return the same as the others here, and the
erasePage
calls solved it. -
Couldn't there be false positives caused by a fluctuating magnetic field that the magnetometer picks up (or something like that, I'm not educated on magnetism)? It could appear as if the wearer was active, even though the person was immobile.
Also, isn't this a field many are trying to get into ("e-Health")? There could be accelerometers out there that specialise at detecting falls.
-
I made a noob mistake when publishing the package to NPM, it probably didn't work for anyone else but me :/ It should be fixed now, hopefully it works for everyone. It does require Node v6 or greater.
-
-
-
This may be overkill, but I had an idea for something like Chrome Experiments meets JSFiddle for Puck.js. Where you can browse interesting projects and examples, try them out on your puck right away, and then edit the code. And easily add your own experiments/projects to the collection.
But that sounds like a lot of work :)
What I'd want to see on puck-js.com/go is an initial example that's super easy but immediately demonstrates how fun it can be. For example, after connecting, simply hit the button and something magical happens on the page. Maybe not unicorns and rainbows, but something crazy would be fun.
Then, being mightily impressed, I'd like to be able to write some code myself, and see what other people are making. So there has to be links to the Web IDE and some good examples.
But rather than just linking to examples, maybe having a short presentation of each? That way it's easier to get an impression of what they actually do, and what's possible to make with Puck.js.
-
Nice, @daphtdazz! I was wondering how long till I'd be able to program pucks from my iPad :)
Purchased. -
I've looked into loading Espruino modules straight from espruino.com/modules, and while that seems possible, I think It will have to wait untill I actually need is, I have enough on my plate as it is.
If someone else wants to give it a shot, the relevant Rollup hooks appear to be
resolveId
andload
. -
You're right of course! I think I skipped the
transformForEspruino
processor call when I was trying to get things to work, and honestly hadn't really understood how the plugin system works until now. Now that the processor call is back my code follows the same pipeline assendCode
, and it seems to be doing just the same (I'm not calling it directly because I want more control over output).Some more changes:
- Better options
- Now supports
reset
,save
,setTime
,BLE
,audio
,baudRate
andthrottle
(all with Espruino's defaults) - Any other Espruino config options may be set using their uppercase names directly
- Added
output
option for showing the output from Espruino when sending code
- Now supports
- Detects and reports any uncaught JS errors after code has been sent (very useful)
- Prettier CLI with colours and all
I also figured out how to minify it even further, and added a tip for how to configure Uglify to be even uglier on the project page.
- Better options
-
Yea, I noticed that it could be minified even further. That's up to the Uglify plugin to do, I'll see whether it can be configured to be more ugly.
At the moment you have to manually download the modules, but I think it might be possible to automatically download Espruino modules like the Web IDE does, I'll see what I can do! Would be very nice if this could work just like the Web IDE, that's a good benchmark :)
I don't think setting
SAVE_ON_SEND
would work, as I'm skipping the part of EspruinoTools that does minification, which is what calls the plugin for saving, if I recall correctly. Can I call that plugin directly somehow? -
And with that configuration, here's the DS18B20 module's example rewritten in modern JS:
import { connect } from './modules/DS18B20.js' let ow = new OneWire(A1) let sensor = connect(ow) setInterval(() => { sensor.getTemp(temp => console.log('Temp is ' + temp + '°C')) }, 1000)
The same code bundled with the module, uglified and sent to my Espruino after running
rollup -c
:function DS18B20(t,e){if(this.bus=t,void 0===e?this.sCode=this.bus.search()[0]:parseInt(e).toString()==e&&e>=0&&e<=126?this.sCode=this.bus.search()[e]:this.sCode=e,!this.sCode)throw new Error("No DS18B20 found");this.type=parseInt(this.sCode[0]+this.sCode[1])}var C={CONVERT_T:68,COPY:72,READ:190,WRITE:78};DS18B20.prototype._r=function(){var t=this.bus;return t.select(this.sCode),t.write(C.READ),t.read(9)},DS18B20.prototype._w=function(t,e,s){var r=this.bus;r.select(this.sCode),r.write([C.WRITE,t,e,s]),r.select(this.sCode),r.write(C.COPY),r.reset()},DS18B20.prototype.setRes=function(t){var e=this._r();t=[31,63,95,127][E.clip(t,9,12)-9],this._w(e[2],e[3],t)},DS18B20.prototype.getRes=function(){return[31,63,95,127].indexOf(this._r()[4])+9},DS18B20.prototype.isPresent=function(){return this.bus.search().indexOf(this.sCode)!==-1},DS18B20.prototype.getTemp=function(t){function e(e){for(var s=e._r(),r=0,i=0;i<8;i++){r^=s[i];for(var o=0;o<8;o++)r=r>>1^140*(1&r)}var n=null;return r==s[8]&&(n=s[0]+(s[1]<<8),32768&n&&(n-=65536),n/=10==e.type?2:16),t&&t(n),n}if(this.bus.select(this.sCode),this.bus.write(C.CONVERT_T,!0),!t)return e(this);var s={9:94,10:188,11:375,12:750};setTimeout(e,s[this.getRes()],this)},DS18B20.prototype.searchAlarm=function(){return this.bus.search(236)},DS18B20.prototype.setAlarm=function(t,e){t--,t<0&&(t+=256),e<0&&(e+=256);var s=this._r();this._w(e,t,s[4])};var connect=function(t,e){return new DS18B20(t,e)};let t=new OneWire(A1),e=connect(t);setInterval(()=>{e.getTemp(t=>console.log("Temp is "+t+"°C"))},1e3);
Not so pretty anymore..
-
In order to use Espruino modules (and other CommonJS modules) a few extra steps are required, especially if you also want to uglify/minify the code. This assumes you already have Node, npm and Rollup installed.
First, install the plugins…
npm install rollup-plugin-espruino npm install rollup-plugin-commonjs npm install rollup-plugin-uglify
You need to use the "harmony" branch of the
uglify-js
library for the uglify plugin to support ES modules. This will fetch it from GitHub:npm install mishoo/UglifyJS2#harmony
Finally, add the following configuration to your Rollup config (
rollup.config.js
if using the CLI):import espruino from 'rollup-plugin-espruino' import commonjs from 'rollup-plugin-commonjs' import uglify from 'rollup-plugin-uglify' import { minify } from 'uglify-js' export default { entry: 'src/main.js', dest: 'dist/bundle.js', format: 'es', plugins: [ commonjs(), uglify({}, minify), espruino(), ], }
Here I'm passing the "harmony" branch of
uglify-js
asminify
to theuglify
plugin.And with that, it should work as expected. In harmony.
Luckily, other plugins are more straight forward.
-
I've made a plugin for Rollup that lets you push the resulting code straight to Espruino devices.
Rollup is a module bundler, which takes JS modules (preferably ES modules) and bundles them into one file. While doing so, it employs tree-shaking and static analysis to remove unused code, resulting in a file that contains only the bare minimum. Perfect for Espruino :)
It supports plugins, so you can easily add minification of code, linting, support for CoffeScript – and thankfully, support for CommonJS modules, which is the format of Espruino's modules.
Basically, this allows you to structure your Espruino projects using modern ES modules, and have Rollup bundle it all up and send the resulting code to Espruino in one command.
I've only tested it on Puck.js so far, but it's based on code from EspruinoTools' CLI, so hopefully it works for all supported devices. There's also one more feature I'd like to add, the ability to save after sending.
If this sounds useful, try it out and let me know how it works (or doesn't work) :)
-
Software: VS Code as IDE, iTerm as terminal set up something like this (OS X), Sketchup for 3D modeling, Espruino's CLI, and (shameless plug) my new plugin for Rollup
Hardware: Hakko FX888D soldering station
Services: GitLab/GitHub for projects, Netlify for hosting of static sites
Sites: Espruino's reference and forum of course, Hackaday for inspiration, Adafruit for inspiration and guides, Stack Overflow and other Stack Exchange sites for answers, FindChips for finding chip retailers and prices, eBay for cheap parts from Asia -
I've had good experiences with Tictail. If you just overlook the hipsters who use it and the marketplace, it's actually pretty nice. Takes payments from PayPal and Stripe, with no additional fees, and has all the features you mentioned. Some through addons which cost very little, otherwise it's free. Easy to edit the design of your store front too.
Of course, you'd still have to manage shipping, accounting, etc yourself.
-
@CriscoCrusader Ah, sorry! I only looked for
require('espruino')
at the top of the code, and thought you usedserialport
directly. Never mind me then :)
Found this interesting tidbit in a thread some months back:
I've been secretly hoping for an Espruino board based on nRF91, so if this happens I'd be first in line to buy a few!
I know nRF91 is not production ready yet, but planned to be released later this year if I'm not mistaken. Is it still something you're just considering, or do you have concrete plans for doing something with it?
LTE M/NB-IoT is being rolled out at the end of the year here in Norway, which is nicely timed with the release of nRF91. Safe to say, I'd be very interested in an Espruino product with nRF91 some time thereafter :)
Just let me know if there's anything I can do to help, or if you're interested in hearing what I'm looking for in an LTE M/NB-IoT solution like this.