Open gpdaniels opened 3 years ago
Hi! I've investigated this a bit. I have a small dump of a short bluetooth session between Android Robot Inventor and the hub. So far I see it's working via BT, not BLE since it uses RFCOMM. RFCOMM is a part of BT stack.
Here is what I found so far.
{"i":"....","m":"get_hub_info","p":{}}
{"i":"....","m":"program_modechange","p":{"mode":"play"}}
{"i":"....","m":"program_terminate","p":{}}
{"i":"....","m":"reset_program_time","p":{}}
{"i":"....","m":"scratch.display_animation","p":{"frames":["00900:06960:99099:06960:00900","00900:06960:99099:06960:00900","00900:06960:99099:06960:00900","00900:06960:99099:06960:00900"],"async":false,"delay":500,"fade":5,"loop":false}}
{"i":"....","m":"scratch.display_clear","p":{}}
{"i":"....","m":"scratch.display_rotate_orientation","p":{"orientation":"4"}}
{"i":"....","m":"scratch.motor_go_to_relative_position","p":{"port":"A","position":0,"speed":35,"stall":true,"stop":1}}
{"i":"....","m":"scratch.motor_pwm","p":{"port":"A","power":50,"stall":true}}
{"i":"....","m":"scratch.motor_pwm","p":{"port":"A","power":-50,"stall":true}}
{"i":"....","m":"scratch.motor_run_timed","p":{"port":"A","time":1000,"speed":50,"stall":true,"stop":1}}
{"i":"....","m":"scratch.motor_set_position","p":{"port":"A","offset":0}}
{"i":"....","m":"scratch.motor_set_position","p":{"port":"A","offset":73}}
{"i":"....","m":"scratch.motor_start","p":{"port":"A","speed":80,"stall":true}}
{"i":"....","m":"scratch.motor_start","p":{"port":"A","speed":-80,"stall":true}}
{"i":"....","m":"scratch.motor_stop","p":{"port":"A","stop":1}}
{"i":"....","m":"scratch.play_sound","p":{"path":"/extra_files/Hydraulics Up","volume":10,"freq":16000,"wait":false}}
{"i":"....","m":"scratch.reset_yaw","p":{}}
{"i":"....","m":"scratch.ultrasonic_light_up","p":{"port":"F","lights":[0,0,0,0]}}
{"i":"....","m":"scratch.ultrasonic_light_up","p":{"port":"F","lights":[100,100,100,100]}}
{"i":"....","m":"trigger_current_state","p":{}}
i
— Random message ID (consists of 4 chars from range: 0-9, a-z, A-Z, -, _) this is needed for identification of response message from the hubm
— Command to be executed. This is mapped to the methods inside commands/*
of the filesystem of the hub. The methods begin with handle_...
.p
— Object with parameters specific to a command{"m":0,"p":[
[75, [0, 0, 179, 0]],
// Port A (state of a motor)[0, []],
// Port B[0, []],
// Port C[0, []],
// Port D[0, []],
// Port E[0, []],
// Port F[-8, 0, 1021],
// compass[6, 10, -5],
// acceleration[0, 0, 0],
// z rot, long side incline, short side incline"",
9932]}
{"m":2,"p":[8.323, 100, false]}
// Battery status message, sent once a second{"m":4,"p":"down"}
— event when hub gets flipped to a side{"m":4,"p":"doubletapped"}
I found a few additional commands I thought might be useful:
{"i":"....","m":"program_execute","p":{"slotid": 1}}
- Starts program saved to slot 1.{"i":"....","m":"program_terminate","p":{}}
- Stops currently running program.{"i":"....","m":"get_storage_status","p":{}}
- Returns current storage and slot information.{"i":"....","m":"move_project","p":{"old_slotid": 1, "new_slotid": 2}}
- Moves program from slot 1 to slot 2.{"i":"....","m":"remove_project","p":{"slotid": 1}}
- Deletes program from slot 1.Hi. Does sending these commands work with the factory firmware or do I have to flush something custom?
I have a research project using these 51515 hubs as targets, and I have been looking for a way to control them through a desktop application without the need of LEGO app.
@brabebhin These commands work with the default firmware over Bluetooth or USB. Most commands should work for both 51515 and Spike hubs, but there might be a few that are system-specific since the firmware varies slightly.
Cool thank you for the information. One more question: i know in older lego sets the serial message had to be prefixed with the length of the message, does this apply here as well?
Thanks
Desktop app:
Android app: