JopieK

Powered Up - A tear down...

Recommended Posts

Thanks for all the great info in this thread, and the wonderful NodeJS library from @Mr Hobbles.  I've been working on an async-event-based Python library that presents a similar interface to control these hubs that works under OS X (should work under Linux too); if there's any interest, I can probably spend some time open sourcing it once I get it a bit more polished. 

Share this post


Link to post
Share on other sites

Great! I'm glad to see that people are getting some use of it. :)

As for what's next on it, I have two ongoing features. The first is I plan to split off device (motor, sensor, lights) control into a separate object attached to the hub rather than being methods on the hub. This should allow for a bit of a cleaner interface.

The second is Web Bluetooth support. The Web Bluetooth spec is still in its infancy, and is only really supported by Chrome at the moment, and in a very incomplete state, so I've been a bit stuck on this for a while. But thanks to LEGO's release of the Wireless Protocol a few weeks back, I may have just discovered a way to get the info I need from the hub without relying on the missing Web Bluetooth features. The main advantage of this is that it should allow the library to be used directly in the browser, without a server, on both desktop and mobile. Powered UP device control just by visiting a website in your browser! :)

Edited by Mr Hobbles

Share this post


Link to post
Share on other sites
On 1/18/2019 at 8:29 PM, Mr Hobbles said:

The main advantage of this is that it should allow the library to be used directly in the browser, without a server, on both desktop and mobile. Powered UP device control just by visiting a website in your browser! :)

 That sounds amazing!

Share this post


Link to post
Share on other sites

Wow, just found this thread. At first I wasn't excited about powered up but now I am.

Edited by Bmr4life

Share this post


Link to post
Share on other sites

Hi,

I just tried to get node-poweredUp running, but with my zero knowledge of Linux that's quite difficult. What I have:

pi@raspberrypi:~ $ node -v
v0.10.29
pi@raspberrypi:~ $ npm version
{ npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.1',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '6.8.275.32-node.12',
  zlib: '1.2.11' }
pi@raspberrypi:~ $ npx -v
6.4.1

Whatever that means ;-)

And what I get is below, what is wrong with my installation?
Is there a step by step tutorial how to get a .js running?

pi@raspberrypi:~ $ node al.js

/home/pi/al.js:20  /* This is vernie_remote.js

let vernie = null;
    ^^^^^^
SyntaxError: Unexpected identifier
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
pi@raspberrypi:~ $ node cb.js

/home/pi/cb.js:4  /* This is the "samle usage"
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
                                      ^
SyntaxError: Unexpected token >
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
pi@raspberrypi:~ $

Edited by Lok24

Share this post


Link to post
Share on other sites

@Lok42 Here's the simplest steps I'd recommend for you:

Create a new folder for your project:
> mkdir puptest

Move into that folder:
> cd puptest

Initialise a new Node.js project:
> npm init -y

Install node-poweredup and save it as a dependency of your project:
> npm install node-poweredup --save

At this point you can now create a new file (maybe call it test.js?) in your project directory - try the sample code. Then run it:
> node test.js

Now turn on one of your hubs and it should connect and activate the motors as described in the sample. Make sure you have two motors attached to ports A and B. :)

Edited by Mr Hobbles

Share this post


Link to post
Share on other sites

Seems that it doensn't work on a RaspberryPi A+ (as you tested with B)
But many thanks for your support.

I'll try later on another hardware (Win 10 did not work as well)

Just an info: the first of dozens of errors:

> usb@1.5.0 install /home/pi/LEGO/JSproject/node_modules/usb
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/tessel/node-usb/releases/download/1.5.0/usb_bindings-v1.5.0-node-v64-linux-arm.tar.gz
node-pre-gyp WARN Pre-built binaries not found for usb@1.5.0 and node@10.15.1 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
make: Entering directory '/home/pi/LEGO/JSproject/node_modules/usb/build'
  CC(target) Release/obj.target/libusb/libusb/libusb/core.o
  CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
  CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
  CC(target) Release/obj.target/libusb/libusb/libusb/io.o
  CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
  CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o
  CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o
../libusb/libusb/os/linux_udev.c:40:21: fatal error: libudev.h: Datei oder Verzeichnis nicht gefunden
 #include <libudev.h
>
                     ^
compilation terminated.
libusb.target.mk:138: recipe for target 'Release/obj.target/libusb/libusb/libusb/os/linux_udev.o' failed
make: *** [Release/obj.target/libusb/libusb/libusb/os/linux_udev.o] Error 1
make: Leaving directory '/home/pi/LEGO/JSproject/node_modules/usb/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/nodejs/node-v10.15.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:189:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Linux 4.1.18+
gyp ERR! command "/usr/local/lib/nodejs/node-v10.15.1/bin/node" "/usr/local/lib/nodejs/node-v10.15.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/home/pi/LEGO/JSproject/node_modules/usb/src/binding/usb_bindings.node" "--module_name=usb_bindings" "--module_path=/home/pi/LEGO/JSproject/node_modules/usb/src/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /home/pi/LEGO/JSproject/node_modules/usb
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error

 

Share this post


Link to post
Share on other sites
1 hour ago, bricks n bolts said:

Looks like you are missing some library for the compiler to work.

Take a look here :

https://stackoverflow.com/questions/17808084/fatal-error-libudev-h-no-such-file-or-directory

 

 

 

 

Yep, I messaged @Lok24 outwith this thread, but I think he needs to install the Noble dependencies first: https://github.com/noble/noble#prerequisites

Share this post


Link to post
Share on other sites
On 6/15/2018 at 6:39 PM, TrainDragon said:

ID1 goes through a resistor, then to port PD6 on the STM8 microcontroller.  According to the datasheet, PD6 is "Analog input 6/UART1 data receive".  ID2 goes through a resistor, then to port PD5 on the STM8 microcontroller, which is "Analog input 5/UART1 data transmit".

I'm testing a few things in the sensor department at the moment, and I'm on the same side here, they probably use the UART function over ID1/ID2.

I guess they are using the inline resistors for two reasons: first, to take care of EMC issues, and second, to protect the chips' ports when probing the ID values of the "no-brainer" parts like train motor and LEDs.

In order to replicate this interface, could you do me a favor and measure those inline resistors on the RX and TX signals?

Has someone already taken apart the color/distance sensor? I'd like to know how they handle pins ID1 and ID2. The Boost motor has two inline resistors, and I expect the sensor to have the same. I'm curious about the resistors values.

On another question: Has someone monitored the serial communication between the Smart Hub and the Sensor? I expect the sensor to come up with a "greeting/Identify" message at bootup/connect, and I remember that the communication between sensor and Smart Hub was basically identical to the BT telegrams. Has anyone gathered any intelligence/experience here?

Share this post


Link to post
Share on other sites
On 1/23/2019 at 7:26 PM, Cosmik42 said:

And I found what I was looking for there: more than a disconnect, a power off:

[0x03 0x00 0x02 0x01]

 

could you please translate this for me into a command like

char-write-req 0x0...  nnnnnn
Thanks.

Edited by Lok24

Share this post


Link to post
Share on other sites
11 hours ago, Lok24 said:

could you please translate this for me into a command like

char-write-req 0x0...  nnnnnn
Thanks.

@Lok24 As said before: I am a total amateur, just beginning to get my head around BLE communication in general and LEGO BLE protocol in particular.

And well - this is running on 18 years old VB6 as you know:wink:. What worked for me was write to the only characteristic relevant for Hub specific things:

"0x04 0x00 0x02 0x01". The first three bytes are comprising the "common message header" (cf. section 3.1 of the official LEGO BLE protocol documentation)

(1) length of message in #bytes when it is shorter than 127 bytes in total, here = 0x04 bytes
(2) always 0x00 (may change in future releases),
(3) Message Type, which is here of type "hub action" = 0x02

and then the actual action (cf. section 3.6.2) "switch off hub" = 0x01

Is that what you were asking for?

Best
Thorsten   

 

Edited by Toastie

Share this post


Link to post
Share on other sites
14 hours ago, Toastie said:

@Lok24

"0x04 0x00 0x02 0x01".

Is that what you were asking for?

 

Not really :classic:

char-write-req xxxx 04000201 , the value is given (04000201), but xxxx is the handle. Which one?

 

Share this post


Link to post
Share on other sites

just found:

char-write-req 000b 04000201 for handheld

char-write-req 000e 04000201 for Smart Hub

Edited by Lok24

Share this post


Link to post
Share on other sites
7 hours ago, Lok24 said:

just found:

char-write-req 000b 04000201 for handheld

char-write-req 000e 04000201 for Smart Hub

Sorry - the handle part is handled:hmpf: by my client control

(It "discovers" the handles and assigns "IDs" for it - these contain the 000b and 000e part as well … did not know that these were handles. As said, I guess they made this contrl for dummies)

But: Nice that is works!

Best
Thorsten 

Share this post


Link to post
Share on other sites
On 9/8/2018 at 11:35 AM, JopieK said:

I ran into a problem with one of the Duplo train hubs. I borrowed one from an educational set, from the outside (HUB 5) it is identical to the one from the Duplo steam train though. The one from the steam train set recognizes all colors, the borrowed one only recognizes blue (water) and white (light) but ignores reverse (green), stop (red) and whistle (yellow). I replace the batteries to be sure but same behavior. It seems to be faulty, I also can't update it through the Duplo app or something.

Have you tried to read the firmware version? Maybe one of them is just outdated.

Share this post


Link to post
Share on other sites
13 hours ago, treczoks said:

Have you tried to read the firmware version? Maybe one of them is just outdated.

Well it was a preliminary version, but I posted it in august and now it is februari. LEGO provided me with a final version and that one works great!

Share this post


Link to post
Share on other sites
1 hour ago, JopieK said:

Well it was a preliminary version, but I posted it in august and now it is februari. LEGO provided me with a final version and that one works great!

Hi,

very interesting.
First: you got a complete new Train Hub, or is there FW as a file and a method to load it?
Second: There seems to be no final version that works, this is why the set is not sold any more
(problem: when climbing the bridge "green" is detected and train changes direction)

FW of Hub No.4: Strange as well.
I have two here, both showing version 03 01.

But one reports as "Hub No. 4", the other one as "Smart Hub".

Spooky.

 

 

 

 

 

Share this post


Link to post
Share on other sites

A complete train hub? No they shipped me the complete 45025 Coding Express set, so really really nice service!

Share this post


Link to post
Share on other sites
4 hours ago, Lok24 said:

 Second: There seems to be no final version that works, this is why the set is not sold any more
 (problem: when climbing the bridge "green" is detected and train changes direction)

Interesting. Which set are you talking about? Afaik, all the Duplo train sets are still for sale, including the Education coding express.

Share this post


Link to post
Share on other sites

I'm searching for 10875 in German S@H - no result displayed (tracks and bridge are shown)

https://shop.lego.com/de-DE/search?q=10875

on US-Site: out of stock

Got my information from Service, and clients describe behaviour in their comments

 

Share this post


Link to post
Share on other sites
59 minutes ago, Lok24 said:

I'm searching for 10875 in German S@H - no result displayed (tracks and bridge are shown)

https://shop.lego.com/de-DE/search?q=10875

 on US-Site: out of stock

 Got my information from Service, and clients describe behaviour in their comments

  

Wow that's a good find, I just checked out the UK store too, and indeed, both 10874 and 10875 are gone. If indeed the problem is the color sensor, I wonder why a firmware update couldn't fix it? Interesting!

Share this post


Link to post
Share on other sites
10 hours ago, Mr Hobbles said:

Wow that's a good find, I just checked out the UK store too, and indeed, both 10874 and 10875 are gone. If indeed the problem is the color sensor, I wonder why a firmware update couldn't fix it? Interesting!

It will be fixed by a firmware upgrade, but the typical Duplo buyer doesn't connect to WLAN via App.....

The poblem isn't sensor, I assume it's the combination of Distance and RGB, which has to  be a bit better adjusted.

So the change a 5 to a 7 somewere. That's why they say it will be in store again - in Summer!

 

Share this post


Link to post
Share on other sites
On 2/11/2019 at 5:21 AM, treczoks said:

On another question: Has someone monitored the serial communication between the Smart Hub and the Sensor? I expect the sensor to come up with a "greeting/Identify" message at bootup/connect, and I remember that the communication between sensor and Smart Hub was basically identical to the BT telegrams. Has anyone gathered any intelligence/experience here?

Yes, this is the essence of the decoder project on my github page.  I've posted a bunch of sample data captures there.  If you install Sigrok and my python plugin, you should be able to easily visualize the communications between the hub and sensor.

To directly answer your question, I did find a possible identification marker at connect for the motor:

# from handlers.py ...

# Motor initialization marker?
# The Hub sends this message to the Motor, then the Motor echoes it back to the Hub
# 0x54 22 00 10 20 B9

 but did not find a similar marker for the color/distance sensor.

 

Edited by TrainDragon
Added clarity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.