Puck.js data logging

Posted on
  • We have an application where we would like to store the output of the accelerometer for relatively long periods of time (30 min or so) at 50ms intervals so the onboard flash won't do the trick. How do I pipe the output of the Web IDE to a file residing on the laptop's file system? All the file operation functions in the API seem to be related to local (to the Puck.js) memory. I could copy and paste from the console, but not sure how large that buffer is and anyway that's a pain.


    1 Attachment

    • Screenshot 2021-06-10 135511.png
  • There is command line tool, look for Espruino Command-line tool in

    http://www.espruino.com/Programming

    https://www.npmjs.com/package/espruino

    you could redirect the output to a file.

  • Thanks for that tip, unfortunately I'm having some trouble installing the CLI b/c I can't install winnus. Log output below, any ideas?

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Try the new cross-platform PowerShell https://aka.ms/pscore6
    
    PS C:\Users\tony> npm install -g espruino
    npm WARN deprecated tar.gz@1.0.7: ⚠️  WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issue­s/3142
    npm WARN deprecated node-pre-gyp@0.17.0: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
    npm WARN deprecated har-validator@5.1.5: this library is no longer supported
    npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
    C:\Users\tony\AppData\Roaming\npm\esprui­no -> C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\bin\espruino-cli.js
    
    > usb@1.7.1 install C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\usb
    > prebuild-install --runtime napi --target 4 --verbose || node-gyp rebuild
    
    prebuild-install info begin Prebuild-install version 5.3.6
    prebuild-install info looking for cached prebuild @ C:\Users\tony\AppData\Roaming\npm-cache\­_prebuilds\96eb89-usb-v1.7.1-napi-v4-win­32-x64.tar.gz
    prebuild-install info found cached prebuild
    prebuild-install info unpacking @ C:\Users\tony\AppData\Roaming\npm-cache\­_prebuilds\96eb89-usb-v1.7.1-napi-v4-win­32-x64.tar.gz
    prebuild-install info unpack resolved to C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\usb\build\R­elease\usb_bindings.node
    prebuild-install info install Successfully installed prebuilt binary!
    
    > @abandonware/bluetooth-hci-socket@0.5.3-­7 install C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\bluetooth-hci-socket
    > node-pre-gyp install --fallback-to-build
    
    node-pre-gyp WARN Using request for node-pre-gyp https download
    node-pre-gyp WARN Tried to download(404): https://github.com/abandonware/node-blue­tooth-hci-socket/releases/download/0.5.3­-7/bluetooth_hci_socket-0.5.3-7-node-v72­-win32-x64.tar.gz
    node-pre-gyp WARN Pre-built binaries not found for @abandonware/bluetooth-hci-socket@0.5.3-­7 and node@12.18.3 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
    Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
      win_delay_load_hook.cc
      bluetooth_hci_socket.vcxproj -> C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\blu
      etooth-hci-socket\build\Release\\bluetoo­th_hci_socket.node
      Copying C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\bluetooth-hci-socket\build\
      Release\/bluetooth_hci_socket.node to C:/Users/tony/AppData/Roaming/npm/node_m­odules/espruino/node_modules/@abandonwa
      re/bluetooth-hci-socket/lib/binding\blue­tooth_hci_socket.node
              1 file(s) copied.
    
    > @abandonware/noble@1.9.2-14 install C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\noble
    > node-gyp rebuild
    
    
    C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\noble>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modul­es\npm-lifecycle\node-gyp-bin\\..\..\nod­e_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modul­es\node-gyp\bin\node-gyp.js" rebuild )
    Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
      win_delay_load_hook.cc
      noble.vcxproj -> C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\noble\build\Releas
      e\\noble.node
    
    > winnus@0.0.6 install C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\winnus
    > node-gyp rebuild
    
    
    C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\winnus>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modul­es\npm-lifecycle\node-gyp-bin\\..\..\nod­e_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modul­es\node-gyp\bin\node-gyp.js" rebuild )
    Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
      winnus.cpp
      win_delay_load_hook.cc
    C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\winnus\cpp\­winnus.cpp(39,11): error C2039: 'Handle
    ': is not a member of 'v8' [C:\Users\tony\AppData\Roaming\npm\node_­modules\espruino\node_modules\winnus\bui­ld\winnus.vc
    xproj]
    C:\Users\tony\AppData\Local\node-gyp\Cac­he\12.18.3\include\node\v8-platform.h(16­): message : see declaration of 'v8' [C
    :\Users\tony\AppData\Roaming\npm\node_mo­dules\espruino\node_modules\winnus\build­\winnus.vcxproj]
    ...
    gyp ERR! build error
    gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bi­n\MSBuild.exe` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modul­es\node-gyp\lib\build.js:194:23)
    gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    gyp ERR! System Windows_NT 10.0.19042
    gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_m­odules\\node-gyp\\bin\\node-gyp.js" "rebuild"
    gyp ERR! cwd C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\winnus
    gyp ERR! node -v v12.18.3
    gyp ERR! node-gyp -v v5.1.0
    gyp ERR! not ok
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: winnus@0.0.6 (node_modules\espruino\node_modules\winn­us):
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: winnus@0.0.6 install: `node-gyp rebuild`
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
    
    + espruino@0.1.38
    added 28 packages from 102 contributors and updated 1 package in 26.988s
    PS C:\Users\tony> espruino -d Puck.js
    Espruino Command-line Tool 0.1.38
    -----------------------------------
    
    Searching for device named "Puck.js"
    undefined:55
        } else throw err;
               ^
    
    Error: No compatible USB Bluetooth 4.0 device found!
        at BluetoothHciSocket.bindUser (C:\Users\tony\AppData\Roaming\npm\node_­modules\espruino\node_modules\@abandonwa­re\bluetooth-hci-socket\lib\usb.js:91:11­)
        at BluetoothHciSocket.bindRaw (C:\Users\tony\AppData\Roaming\npm\node_­modules\espruino\node_modules\@abandonwa­re\bluetooth-hci-socket\lib\usb.js:47:8)­
        at Hci.init (C:\Users\tony\AppData\Roaming\npm\node_­modules\espruino\node_modules\@abandonwa­re\noble\lib\hci-socket\hci.js:120:18)
        at NobleBindings.init (C:\Users\tony\AppData\Roaming\npm\node_­modules\espruino\node_modules\@abandonwa­re\noble\lib\hci-socket\bindings.js:93:1­3)
        at C:\Users\tony\AppData\Roaming\npm\node_m­odules\espruino\node_modules\@abandonwar­e\noble\lib\noble.js:61:24
        at processTicksAndRejections (internal/process/task_queues.js:79:11)
    
  • Ahh, ok - installing those tools on Windows is a bit of a pain.

    What I'd suggest is that you make a simple Web Bluetooth page. The code you need is basically what's in the second code example on https://www.espruino.com/Data+Collection­#automatically-recovering-data

    And there's a bit more info on getting started on https://www.espruino.com/Web+Bluetooth

    However I've been asked about this a few times now, and it does make a lot of sense to have this functionality inside the Web IDE. I'll look into whether I can get an update in quickly to add the feature.

  • However I've been asked about this a few times now, and it does make a lot of sense to have this functionality inside the Web IDE. I'll look into whether I can get an update in quickly to add the feature.

    That would be great to have!

  • Hey, while you are there, what about adding "simple" graph like one in MakeCode or Arduino Ide? :)

  • Ok, it's live now!

    • https://www.espruino.com/ide/ (you may need to ctrl+reload the page to force it to load the new version)
    • Settings -> General -> Terminal Log Icon
    • There's a new icon in the left of the terminal. Click it and you can start logging, then later you can save to a file.

    It doesn't 'stream' to a file, but realistically you could record hundreds of megabytes of data without running into any problems (and this way it's easy to integrate with the existing codebase)

  • Wow, many thanks :-)
    It works fine at least with emulator.
    Finally saving dumps of SPI or internal flash is easy.

  • Nice!
    What about optionally saving to localStorage, so you don't lose data if you accidentally close the tab, forget it, etc?
    https://github.com/espruino/EspruinoWebI­DE/pull/252 :)

  • Absolutely amazing! In all my years I've never seen such stellar support! It works perfect, thank you so much! We're working on an athlete tracking system using UWB and we need an independent way to verify system requirements when it comes to location and IMU data, and the Puck.js with this logging capability is perfect for the job. What would have taken a month with other industrial instrumentation solutions is working with literally 2 hours of effort at a fraction of the cost, I'm forever grateful and will be keeping on eye on what new capabilities you deliver.

  • Btw, started working on a simple graphing solution like in the Micro:bit editor. Smoothie Charts, used by Micro:bit editor looks pretty nice for simple real-time graphing: http://smoothiecharts.org (MIT license)

    Input lines either JSON, for example {foo: 10, bar:15}, or what the Micro:bit does: x:42. Altho thinking about a prefix to either ignore certain lines, or process only certain lines. Could be a config options.
    One graph per data stream, because Smoothie Charts doesn't support labels / legends, and your values can be vastly different.

    A small difference compared to Micro:bit: I would open a popup, so you can resize or place the graphs where you want.

    Ideas, suggestions?

  • Thanks! Glad that's worked so well for you!

    @AkosLukacs merged - thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Puck.js data logging

Posted by Avatar for user129960 @user129960

Actions