zdila / scratch-link-ble-linux

Scratch Link for BLE devices under Linux.
4 stars 0 forks source link

Τhe WeDo 2.0 motor does not start #2

Open grigorism opened 2 years ago

grigorism commented 2 years ago

I have successfully connected a Lego WeDo 2.0 hub, following the instructions (Node.js v17.3.0). I can change the light color (command "set light color to..."), but I can not start the motor. In the terminal is printed the message:

Message: {
  jsonrpc: '2.0',
  method: 'write',
  params: {
    serviceId: '00004f0e-1212-efde-1523-785feabcd123',
    characteristicId: '00001565-1212-efde-1523-785feabcd123',
    message: 'BQM=',
    encoding: 'base64'
  },
  id: 464
}
zdila commented 2 years ago

Thanks for the report. It is interesting because if one command is processed (light color) then I would expect all other commands to be processed as well. I will try to add some more logging so you can collect and send me more details.

zdila commented 2 years ago

Please try with the latest changes.

zdila commented 2 years ago

Run with npm run debug to get debug logs.

grigorism commented 2 years ago

Hello Martin, i tried the newer version with the debug option. Same behavior, the motor doesn't start. Here are the logs:

~/scratch-link-ble-linux$ npm run debug

> scratch-link-node-ble@1.0.0 debug
> node . --debug

Discovering false
WebSocket connection
RPC Received: {
  id: 0,
  method: 'discover',
  params: {
    filters: [ [Object] ],
    optionalServices: [ '00004f0e-1212-efde-1523-785feabcd123' ]
  }
}
Starting discovery
RPC Sending: { id: 0, result: null }
Adapter prop changed org.bluez.Adapter1 { Discovering: Variant { signature: 'b', value: true } }
Discovering true
iface /org/bluez undefined
iface /org/bluez/hci0 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C LPF2 Smart Hub 2 I/O
Device property org.bluez.Device1 { RSSI: Variant { signature: 'n', value: -32 } }
RPC Sending: {
  method: 'didDiscoverPeripheral',
  params: {
    peripheralId: '/org/bluez/hci0/dev_60_77_71_47_20_7C',
    name: 'LPF2 Smart Hub 2 I/O',
    rssi: -32
  }
}
RPC Received: {
  id: 1,
  method: 'connect',
  params: { peripheralId: '/org/bluez/hci0/dev_60_77_71_47_20_7C' }
}
Stopping discovery
Connecting to device /org/bluez/hci0/dev_60_77_71_47_20_7C
Adapter prop changed org.bluez.Adapter1 { Discovering: Variant { signature: 'b', value: false } }
Discovering false
Connected: true
iface /org/bluez/hci0/dev_60_77_71_47_20_7C undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0008 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0008/char0009 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0008/char0009/desc000b undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char000d undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char000d/desc000f undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0010 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0010/desc0012 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0010/desc0013 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0014 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0014/desc0016 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0014/desc0017 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0018 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0018/desc001a undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0018/desc001b undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char001c undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char001c/desc001e undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char001c/desc001f undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0020 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0020/desc0022 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0020/desc0023 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0024 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0024/desc0026 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0027 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char0027/desc0029 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char002a undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char002a/desc002c undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char002d undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service000c/char002d/desc002f undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0031 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0031/desc0033 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0031/desc0034 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0035 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0035/desc0037 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0035/desc0038 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0039 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char0039/desc003b undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char003c undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service0030/char003c/desc003e undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service003f undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service003f/char0040 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service003f/char0042 undefined
iface /org/bluez/hci0/dev_60_77_71_47_20_7C/service003f/char0044 undefined
ServicesResolved: true
RPC Sending: { id: 1, result: null }
Found GATT Characteristics: 00002a05-0000-1000-8000-00805f9b34fb
Found GATT Characteristics: 00001524-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001526-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001527-1212-efde-1523-785feabcd123
Found GATT Service: 00001801-0000-1000-8000-00805f9b34fb
Found GATT Service: 00001523-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001528-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001529-1212-efde-1523-785feabcd123
Found GATT Characteristics: 0000152a-1212-efde-1523-785feabcd123
Found GATT Characteristics: 0000152b-1212-efde-1523-785feabcd123
Found GATT Characteristics: 0000152c-1212-efde-1523-785feabcd123
Found GATT Characteristics: 0000152d-1212-efde-1523-785feabcd123
Found GATT Characteristics: 0000152e-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001560-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001561-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001563-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00001565-1212-efde-1523-785feabcd123
Found GATT Characteristics: 00002a26-0000-1000-8000-00805f9b34fb
Found GATT Characteristics: 00002a28-0000-1000-8000-00805f9b34fb
Found GATT Characteristics: 00002a29-0000-1000-8000-00805f9b34fb
Found GATT Service: 00004f0e-1212-efde-1523-785feabcd123
Found GATT Service: 0000180a-0000-1000-8000-00805f9b34fb
RPC Received: {
  id: 2,
  method: 'write',
  params: {
    serviceId: '00004f0e-1212-efde-1523-785feabcd123',
    characteristicId: '00001563-1212-efde-1523-785feabcd123',
    message: 'AQIGFwEAAAAAAAA=',
    encoding: 'base64'
  }
}
RPC Received: {
  id: 3,
  method: 'write',
  params: {
    serviceId: '00004f0e-1212-efde-1523-785feabcd123',
    characteristicId: '00001565-1212-efde-1523-785feabcd123',
    message: 'BgQDAAD/',
    encoding: 'base64'
  }
}
RPC Received: {
  id: 4,
  method: 'startNotifications',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001527-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 2, result: 11 }
RPC Sending: { id: 3, result: 6 }
RPC Sending: { id: 4, result: null }
RPC Received: {
  id: 5,
  method: 'read',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001528-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 5, result: 'AA==', encoding: 'base64' }
RPC Received: {
  id: 6,
  method: 'read',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001528-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 6, result: 'AA==', encoding: 'base64' }
RPC Received: {
  id: 7,
  method: 'read',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001528-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 7, result: 'AA==', encoding: 'base64' }
RPC Received: {
  id: 8,
  method: 'write',
  params: {
    serviceId: '00004f0e-1212-efde-1523-785feabcd123',
    characteristicId: '00001565-1212-efde-1523-785feabcd123',
    message: 'BQM=',
    encoding: 'base64'
  }
}
RPC Sending: { id: 8, result: 2 }
RPC Received: {
  id: 9,
  method: 'read',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001528-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 9, result: 'AA==', encoding: 'base64' }
RPC Received: {
  id: 10,
  method: 'read',
  params: {
    serviceId: '00001523-1212-efde-1523-785feabcd123',
    characteristicId: '00001528-1212-efde-1523-785feabcd123'
  }
}
RPC Sending: { id: 10, result: 'AA==', encoding: 'base64' }
zdila commented 2 years ago

Thanks for the logs.

Does it work with https://github.com/LLK/scratch-link or other scratch-link? Because in the logs I see no errors.

Are there other commands beside changing light color and starting motor?

grigorism commented 2 years ago

The motor, the sensors and all WeDo commands works fine with official Lego software on an android tablet. Also works fine on my laptop with Ubuntu Linux using Scratch 3 (LLK/scratch-desktop) and kawasaki/pyscrlink.

Using scratch-link-ble-linux the only command I can confirm that works is the "set light color to..." command. Due to the fact that the "turn motor on" command does not work, I can not test commands such as "turn motor off" and "set motor power to ...". I also tried to read the distance with the distance sensor ("distance" command) but it did not work.

I am at your disposal if you want me to try something else. Thank you for your effort so far!

zdila commented 2 years ago

I've fixed startNotifications method. Please try.

grigorism commented 2 years ago

I made three more attempts with the 55a9808 code.

zdila commented 2 years ago

Thanks. I think I will need to test it on a real device. Maybe one day I will have a chance :-)

grigorism commented 2 years ago

Martin, thank you very much for your time. I think you made a very good start in scratch-link development on Node.js. The connection to the WeDo hub is achieved and some of the commands are executed successfully as well!

Is it possible to add some comments to the source code to help us understand how it works? Some may want to try to make the other commands work. Since I have the device in my hands I want to try.

zdila commented 2 years ago

It doesn't work like this that for every device command you must implement it to the scratch-link. Scratch link protocol is defined at https://github.com/LLK/scratch-link/blob/develop/Documentation/BluetoothLE.md and it is universal for all BLE devices.

Scratch Link just translates couple of commands received from WebSocket to BLE. Those are basically just these commands:

grigorism commented 2 years ago

I see. Perhaps the source code from the pyscrlink could help me with that.

zdila commented 2 years ago

BTW I did some refactoring and cleanup. You can try if it fixes anything for you.

grigorism commented 2 years ago

Wow! Total reconstruction! However the motor doesn't start. Tested with ce15472.

suoko commented 4 months ago

Hi, I'm ubuntu 24.04 + node v18.2.0 and with wedo 2.0 everything works great: all sensors, everything!