Avatar for wklenk


Member since Sep 2018 • Last active Mar 2019
  • 5 conversations

Creating smart IoT solutions in the Stuttgart (Germany) area.

Blog: wolfgangklenk.wordpress.com

Most recent activity

  • in Other Boards
    Avatar for wklenk


    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


  • in General
    Avatar for wklenk

    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(() => {
            }, 5000);
        .then((result) => {
        .catch(() => {

    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.

  • in General
    Avatar for wklenk

    There is already a simple State Machine implementation in Espruino:

    State transitions are triggered by calling


    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.

  • in General
    Avatar for wklenk

    I like the idea with having A(), B(), C() function names.

  • in General
    Avatar for wklenk


    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?

  • in Other Boards
    Avatar for wklenk

    Just wrote a small blog entry at https://bit.ly/2Eq15Pk

    1. Why to better use a BLE connection instead of the serial USB connection
    2. How to interface the modem using the "AT" Espruino module
    3. 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.

  • in Other Boards
    Avatar for wklenk

    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 defined

    I 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.

    Actually, that is the thing that Gordon recommended :)