LEGO Hub Library #2
sophiebremer
started this conversation in
Ideas
Replies: 1 comment
-
|
The hub interface differs from the HAT interface. If one keeps the default {"m":"runtime_error","p":[[1, 0, 0, 71], "191f3ad", "4.0.0-gecko.7", "VHJhY2ViYWNrIChtb3N0IHJlY2VudCBjYWxsIGxhc3QpOgogIEZpbGUgInByb3RvY29sL3Vqc29ucnBjLnB5IiwgbGluZSAxLCBpbiBfaGFuZGxlX21lc3NhZ2UKVmFsdWVFcnJvcjogc3ludGF4IGVycm9yIGluIEpTT04K", ""]}Decoding the base64 string leads to JSON-RPCThe hub seems to expect JSON input unlike the CLI of the HAT. According to https://github.com/nutki/spike-tools/blob/master/spikejsonrpc.py#L44 it is some form of JSON-RPC, though not all commands do work (anymore?). Note that the exact spacing of input has to be followed or a syntax error occurs. get_firmware_info ErrorSend: {"m": "get_firmware_info", "p": {}, "i": "6219"}Response: {"i":"6219","e":"eyJtZXNzYWdlIjogImdldF9maXJtd2FyZV9pbmZvIiwgInR5cGUiOiAiVU5LTk9XTl9NRVRIT0QifQ=="}Decoding: {"message": "get_firmware_info", "type": "UNKNOWN_METHOD"}get_storage_status SuccessSend: {"m": "get_storage_status", "p": {}, "i": "8293"}Response: {"i":"8293","r":{"storage": {"available": 2420, "total": 3072, "pct": 22.224, "unit": "kb", "free": 2420}, "slots": {}}}Further testing$ screen /dev/cu.usbmodem3468355632311 115200
# Press CTRL+A SHIFT+H to start screen log recording as `screenlog.0`
# Send {"m": "METHOD_NAME", "p": {}, "i": "1234"}
# Press CTRL+A SHIFT+H to stop screen log recording |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It looks like LEGO SPIKE hubs are accessible via USB. So a library for TypeScript similar to the ones for C#.NET and Python is possible.
Here comes some initial findings. After connecting the hub to the Mac, it powers up and provides two serial interfaces to read and send data. You should not use these interfaces in parallel with the SPIKE.app as this can immediately crash macOS on disconnect.
One can connect to the integrated MicroPython of the blinking hub. Note that the blinking on the hub changes to a constant light after connecting.
I did not verified it yet, but the interfaces might work out of the box similar to the serial interface of the Raspberry Pi GPIO for the Raspberry Pi Build HAT.
Beta Was this translation helpful? Give feedback.
All reactions