-
In a project with focus on low power consumption I use an Espruino Pico and a Microchip RN2483 for LoRaWAN communication.
I send the RN2483 to sleep with a command, and to wake it up from sleep I need to send a "break" condition to the UART and send a 0x55 character for auto-baud detection.
https://www.microchip.com/forums/m930725.aspxI can use Serial1.unset() followed by pulling down TX from some time, then again Serial1.setup(...) and send the 0x55 character.
My issue is that I use the AT command handler wrapped around the Serial1, and doing this break-condition stuff on the Serial1 causes garbage characters piled up in the AT command handler, disturbing future use of this command handler.
Is there an elegant solution to that?
Maybe a command to "clean" the AT command handler?
I cannot re-instantiate the AT command handler, because it consumes too much memory if you do it periodically.Yes, I can send a dummy command to the RN2483's UART and just deal with the fact that it will return an error due to the piled up garbage characters, but that doesn't seam elegant to me. There has to be a more attractive solution :)
-
I think the J-Link adapter is not used for supplying power to the board. The connector on the SWD interface says "VTref", so this is only used to get a "voltage reference" in order to generate the appropriate signal levels when programming. So you definitely need to power the device by other means, e.g. by USB.
-
I am trying to use the "native" Espruino IDE in a company network with no direct access to the internet.
My notebook is running a HTTP proxy called cntlm on port 3128.When transferring code from the IDE to the device, the "required" modules cannot be fetched from the internet.
In Settings -> Communications I can "Enable Proxy",
but what exactly do I have to enter in "Proxy URL" and "Proxy Port" ?
I tried different variations but none of them worked.Best regards,
Wolfgang -
-
-
Please check my recent blog post for a step-by-step explanation how the RAK8212 can be used for prototyping IoT use cases - using the "Digital Twin" representation in AWS IoT Core
https://wolfgangklenk.wordpress.com/2019/04/06/espruino-on-rak8212-create-a-digital-twin-in-aws-iot/
Unfortunately, this article is too big to fit into this forum conversation, so you can start reading here, but have to go to my wordpress blog article to read the full story.
You need a fast, simple and inexpensive way to prototype your IoT use cases?
This article describes how you can achieve this using
- The RAK8212 device with its built-in Quectel BG96 communication module
- Espruino: A JavaScript interpreter for microcontrollers
- Narrowband IoT (NB-IoT): A Low Power Wide Area Network (LPWAN) radio technology standard
- AWS IoT Core and Device Shadow Service ("Digital Twin")
In this example, the RAK8212 device is used as a sensor that periodically sends temperature values to its digital twin in AWS IoT Core. For communication with AWS it uses the MQTT protocol over Narrowband IoT (NB-Iot). The state of a LED on the RAK8212 can be controlled by setting it on the digital twin in AWS IoT.
##Setting up the "thing" in AWS Iot Core
Get yourself an account on AWS, navigate to “AWS IoT” and “Create a single thing”. Describing all the steps would go too far in this article, and AWS has good online documentation. So please follow the steps given in the AWS documentation.In the end, you should have an IoT object (=thing), identified by a name, and a certificate for this object (e.g. 133c075337.cert.pem), a public key (e.g. 133c075337.public.key) and a private key (e.g. 133c075337.private.key). You need to download these three files and activate the certificate.
In the navigation menu of the AWS console, go to “Manage -> Things” and you will see all your things. Select the thing of your choice and, in the navigation menu of the thing, go to “interact”. Note the server address displayed as “Update your Thing Shadow using this Rest API Endpoint”. We will use this as the address of the MQTT server later.
Example Address: a136ivuau4uklv-ats.iot.eu-central-1.amazonaws.com
Also notice the MQTT topics below. They all contain the name of your thing:
Example MQTT Topic: $aws/things/klenk-iot-device/shadow/update
This shows that the name of my thing is “klenk-iot-device”.
##Setting up the example code for RAK8212
The example code is hosted at github:https://github.com/wklenk/rak8212-espruino-nb-iot/blob/master/data-logger-bg96-mqtt.js
Find the JavaScript object that holds the configuration for the NB-IoT radio network connection, e.g.
// NB1 connectivity settings for Vodafone Germany var connection_options = { band: "B20", apn: "vgesace.nb.iot", operator: "26202", debug: false // Print communication with BG96 module to console. };
Adapt this to fit to your NB-IoT network of choice.
Find the JavaScript object that holds the configuration for the MQTT connection to AWS IoT:
var mqtt_options = { // AWS IoT server: 'a136ivuau4uklv-ats.iot.eu-central-1.amazonaws.com', port: 8883, client_id: "klenk-iot-device" };
Adapt the MQTT server (same as address of API endpoint noted down above) and client_id (name of the thing).
Please go on reading at https://wolfgangklenk.wordpress.com/2019/04/06/espruino-on-rak8212-create-a-digital-twin-in-aws-iot/
- The RAK8212 device with its built-in Quectel BG96 communication module
-
-
Hi,
I am looking for a JS library or JS code to animate text or numbers on a matrix display like on the Espruino Pixel. I am thinking about the following kinds of animations:
- scrolling horizontal text in a section of the matrix display
- Digits sliding in/out vertically in a section of the matrix display
- Digits/text fading in/out
- Other funny or artistic transition effects
Does such a library or code already exist?
Where can I get inspriration for funny or artistic transition effects?The cool thing would be, that such a JS library could not only be used on a LCD matrix display, but also on large LED displays or even within web applications running in the web browser. That opens a wide range of opportunities ...
Just share some ideas with me please.
Best regards,
Wolfgang - scrolling horizontal text in a section of the matrix display
-
Some IoT platforms like AWS IoT require you to authenicate with X.509 client certificates when using MQTT as communication protocol for your devices.
The Quectel BG96 module on the RAK8212 already has an embedded MQTT stack, so there is no need for using a MQTT library on the device’s MCU.
The BG96 module supports client and server side authentication using X.509 certificates. The following files must be provided:
- The MQTT client’s client certificate (e.g. 3a34634a38-certificate.pem.crt on AWS IoT)
- The private key of the client (e.g. 3a34634a38-private.pem.key)
- The trusted root CA certificates
The challenge is: How can these files be transfered to the BG96 module’s file system?
Having Espruino installed on the RAK8212, this is not a complicated task. Check my github account at
https://github.com/wklenk/rak8212-espruino-nb-iot
for the JavaScript file upload-ssl-certs-to-bg96.js
All three files have to be provided in PEM format. As this format is in ASCII, you can just cut and paste the contents to the JavaScript source code.
Then transfer the code to the device (using the Espruino IDE) and call function
uploadCertificates();
The files will be saved to the device as cert.pem, key.pem and cacert.pem and can be used in a later step to configure the SSL connection options for the embedded MQTT stack.
____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 1v99 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate > >uploadCertificates(); Connecting Cellular Modem ... =undefined Cellular Modem connected. Files in file system: +QFLST: "cacert.pem",1187 +QFLST: "cert.pem",1224 +QFLST: "key.pem",1679 +QFUPL line: +QFUPL: 1224,380d Uploaded cert.pem +QFUPL line: +QFUPL: 345,1203 Uploaded key.pem +QFUPL line: +QFUPL: 1187,2d19 Uploaded cacert.pem Successfully uploaded SSL certificates to BG96 module. >
- The MQTT client’s client certificate (e.g. 3a34634a38-certificate.pem.crt on AWS IoT)
-
do you have any thoughts about why they might be getting a NOSERVICE message?
I don't know in detail, but what I am missing in the example code is an AT command "AT+COPS" to manually register at the network. I did my tests with NB-IoT capable SIM cards by Vodafone (Germany) and 1NCE. So maybe it is the missing step to register at the network.
I just updated my MQTT via NB-IoT example a few days ago, you can see the sequence of AT commands there. Check it out at
https://github.com/wklenk/rak8212-espruino-nb-iot/blob/master/data-logger-bg96-mqtt.js
-
Im am not completely sure, but there seems to be a simple solution with the already existing Espruino StateMachine module:
Why no do the actual asynchronous work in the "enter" function of each state, and then trigger a state transition in the last "then" block of the chained Promises as follows:
function enterOne() { console.log("Enter One..."); new Promise((resolve, reject) => { setTimeout(() => { resolve('good'); }, 5000); }) .then((result) => { sm.signal(result); }) .catch(() => { sm.signal('bad'); }); };
In the "signal" function of the respective state there could be code that decides - based on the parameter on the "signal" call (here: 'good' or 'bad') - to which new state to transition:
function signalOne(result, e) { console.log("signal one with parameters", result, e); if ('good' === result) { return {state:'Two', wait:(e)?e:0}; } else if ('bad' === result) { return {state:'Error', wait:(e)?e:0}; } };
I think this will fit my needs.
-
There is already a simple State Machine implementation in Espruino:
https://www.espruino.com/modules/StateMachine.jsState transitions are triggered by calling
sm.signal();
However, this expects that the "signal" function of the respective current state synchronously executes some operations and then returns the information what should be the next state to transition to. But how can I handle it if the "signal" function does some asynchronous operations (based on chained Promises). In this case, I cannot immediately decide what the next state should be. I just could return nothing, but then there would be no state transition. I cannot "await" the chained Promises. Actually, I don't see a way to do the state transition at the end of the Promises chain.
Any clever ideas?
Update 2019-01-08 : After trying out different approaches I think I could emit events. So the state transitions would be somehow triggered by the receipt of events. And it is no problem to emit events in chained Promises.
-
-
Hi,
I am using a RAK8212 and want to implement a simple interactive text menu.
I am connected via BLE.The text menu could look like this:
Please enter you choice: 1 Do this 2 Do that You choice>
Bluetooth.read(1) returns immediately.
Bluetooth.on('data', function() {...}) also doesn't work, as the application has no such a thing as a event loop that runs all the time.Any ideas how to create a interactive text menu in the console?
-
Just wrote a small blog entry at https://bit.ly/2Eq15Pk
- Why to better use a BLE connection instead of the serial USB connection
- How to interface the modem using the "AT" Espruino module
- How to create a NB-IoT (NB1) connection in german radio networks (Vodafone, 1NCE)
Feel free to comment there if you like to give feedback.
- Why to better use a BLE connection instead of the serial USB connection
-
What a coincidence: Just wanted to post a new conversation with a similar, if not exactly the same issue:
RAK8212: ReferenceError: "RDY" is not defined
I wrote a small data logger that reads temperature values from the BME280 and sends it via Quectel BG96 modem to an IoT dashboard (Cayenne myDevices).
The code is written "Direct to Flash (Execute at boot)".As long I stay connected with the (native) Espruino IDE via Bluetooth LE, everything goes well. The code creates a socket connection to the IoT dashboard, and data is sent periodically.
But as soon as I power cycle the RAK8212 and stay disconnected, the code starts, but then somehow the code execution is interrupted.
I then tried to catch and store exceptions:
// Deal with any uncaught exceptions process.on('uncaughtException', function (err) { console.log('Error', err); errorStore = err; });
One of the errors found is
ReferenceError: "RDY" is not definedI think I guess what happens: As long as I am connected via Bluetooth LE, then the JavaScript interpreter/console is attached to the serial interface "Bluetooth". But as soon as the RAK8212 runs without something being connected to it, neither via USB nor with Bluetooth LE, then the JavaScript interpreter/console is attached to "Serial1". Unfortunately, when communicating with the modem, "Serial1" is connected with the modem. When the modem has finished booting up, it outputs "RDY" and this is interpreted by the JavaScript interpreter/console. I don't know if there is actually even more malicious interference between modem and JavaScript interpreter/console.
The good news: If I use the following code, everything runs well, even without being connected to the RAK8212:
function onInit() { Bluetooth.setConsole(true); // Don't want to have console on "Serial1" that is used for modem. setupExternalHardware(startDataLogger); }
Actually, that is the thing that Gordon recommended :)
-
-
-
I'm sure you try to save the code before even somethings started to run, correct?
Thanks for the idea with the state machine. In fact, in the end the code has to run unsupervised and therefore it has to be more robust and resilient.
The idea is to build a basic data logger that runs directly from flash when the device is powered on. The data should be sent using protocols like MQTT, CoAP or HTTP.
-
Hi,
I am connecting through Bluetooth.
I removedsetupExternalHardware()
fromonInit()
, but it still freezes.Then I started with a tiny module BG96NB1.js, adding more and more lines of code step by step.
I ended up in just adding lines likeconsole.out("XXXXXXXXXXXXXXXXXXX")
to find out the module size that still worked, while adding just one more line of console.out madesave()
freeze again.The largest size of the overall program I could see was 12261 (0x2FE5) bytes.
Setting up external hardware. Please wait ...
BME280 wiring set up.
Quectel BG96 wiring set up.
save();
=undefined
Compacting Flash...
Calculating Size...
Writing..
Compressed 40000 bytes to 12261
Running onInit()...This makes me assume that there must be some kind of limit at about 12288 (0x3000) bytes.
Could this actually be true?
I can't believe why the application should fit into RAM, but not into flash.process.memory();
={ free: 1620, usage: 880, total: 2500, history: 421, gc: 0, gctime: 5.09643554687, "stackEndAddress": 536927056, flash_start: 0, "flash_binary_end": 382804, "flash_code_start": 471040,
flash_length: 524288 }Found this in https://github.com/espruino/Espruino/blob/master/boards/RAK8212.py :
chip = { 'part' : "NRF52832", 'family' : "NRF52", 'package' : "QFN48", 'ram' : 64, 'flash' : 512, 'speed' : 64, 'usart' : 3, 'spi' : 3, 'i2c' : 2, 'adc' : 1, 'dac' : 0, 'saved_code' : { 'address' : ((118 - 3) * 4096), # Bootloader takes pages 120-127, FS takes 118-119 'page_size' : 4096, 'pages' : 3, 'flash_available' : 512 - ((31 + 8 + 1 + 3)*4) # Softdevice uses 31 pages of flash, bootloader 8, FS 1, code 3. Each page is 4 kb. }, };
Does this mean 3 * 4096 byte only for saved code?
Compared with the Nordic NRF52832 (https://github.com/espruino/Espruino/blob/master/boards/NRF52832DK.py) why does this have 10 pages a 4096 byte for saved code? -
I am currently playing around with a RAK8212 and wrote a module to interface with the Quectel BG96 that is aimed at Narrowband IoT (NB-IoT) communication. I tried my best, but I am a newbie and possibly the code quality is bad ...
But the actual issue is that when I call "save();" the RAK8212 freezes up and I need to press the reset button to get it back into live.
I would appreciate some hints what I am doing wrong or how the issue can be solved.
I have placed the code into a github repository at https://github.com/wklenk/rak8212-espruino-nb-iot
Output:
> ____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 1v99 (c) 2018 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate >Setting up external hardware. Please wait ... BME280 wiring set up. Quectel BG96 wiring set up. >save(); =undefined Compacting Flash... Calculating Size...
-
I have the same behaviour with 1v99 on a RAK8212.
After outputting to console "Calculating Size ..." the execution of the save() function just freezes.
I have set up a function that periodically blinks a LED, but even this blinking stops.
I need to press the reset button and re-connect to get an espruino prompt again.In my case, I have found out that save() works most of the time, but in this particular case my software has registered a callback on incoming data from Serial1 (in my case from the Quectel BG96 modem). I am working with Bluetooth as console. If I throw out the code section that registers that read callback on Serial1, save() works correctly.
So my guess it that save() somehow interferes with Serial1 and then the callback in my software is executed and the complete JS interpreter is blocked.
I currently don't know how to go on finding out what the problem is.
-
RAK8212 with its Quectel BG96 NB-IoT radio communication module, the various built-in sensors (including also GPS) and Espruino are a dream team for efficiently prototyping smart IoT devices.
Things already achieved:
- Get Espruino running on RAK8212 (Espruino RAK8212 page), added a blog post here: https://bit.ly/2x6OdY8
- Got sequence of AT commands to establish NB1 communication on Quectel BG96, working both on Vodafone (Germany) NB-IoT enabled SIM card and 1NCE SIM card (using network of Deutsche Telekom).
Work in progress:
- Small data logger use-case using MQTT protocol and Cayenne myDevices as backend / dashboard.
- Checking out CoAP protocol
- Find good strategies towards reduced power consumption - Could such a device run for years on battery?
- Find good strategies towards minimizing communication - Are only 50MB per year possible?
- Get Espruino running on RAK8212 (Espruino RAK8212 page), added a blog post here: https://bit.ly/2x6OdY8
-
Today I wrote "getting started" instructions at my personal blog at https://bit.ly/2x6OdY8 . I tried to make it very easy even for a beginner to get the Espruino firmware on the RAK8212.
However, now that I go deeper, I would like to know if there are other people playing around with this device? If yes, please contact me.
I am connecting using the "native" Web IDE, using Bluetooth to connect to the device.
Issue #1:
I can't get the GPS example running at http://www.espruino.com/RAK8212#gps. I get ERROR: 516 again and again.Issue #2:
I would like to share experience when it comes to sending/receiving messages via LTE NB-IoT.
Ahh, forget about it. Just sending \r\n on the AT command handler and ignore the returned result works okay for me. Sorry for this post. I tried to delete it, but could not find this feature.