https://toitlang.org/ logo
AdvertisementData parameters
# help
m
I found an inaccuracy in the ble.RemoteScannedDevice parameters when retrieving AdvertisementData., as shown below:
Copy code
micrcx@micrcx-desktop:~/toit/ruuvi_ble$ jag run -d basic ruuvi_ble.toit
Scanning for device with name: 'basic'
Running 'ruuvi_ble.toit' on 'basic' ...
ruuvi_ble.toit:31:35: warning: Deprecated 'AdvertisementData.manufacturer-data'. Use 'Advertisement.manufacturer-specific' instead
      md/ByteArray := device.data.manufacturer-data
                                  ^~~~~~~~~~~~~~~~~
Success: Sent 78KB code to 'basic' in 2.92s
manufacturer-data was replaced with manufacturer-specific, but now a compilation error occurs:
Copy code
micrcx@micrcx-desktop:~/toit/ruuvi_ble$ jag run -d basic ruuvi_ble.toit
Scanning for device with name: 'basic'
Running 'ruuvi_ble.toit' on 'basic' ...
ruuvi_ble.toit:31:35: error: Argument mismatch for 'AdvertisementData.manufacturer-specific'
Block argument not provided
      md/ByteArray := device.data.manufacturer-specific
                                  ^~~~~~~~~~~~~~~~~~~~~
Compilation failed
I've use Jaguar v1.69.0 with Toit SDK v2.0.0-alpha.196.
f
Can you show me a bit more of your code?
m
The code is below. The start-scan function is called from main. Let me know if this isn't enough. I can send you the full application.
Copy code
start-scan :
  scan-task = task:: 
    print "BLE device '$DEVICE_NAME' monitoring has started"
    adapter.central.scan : | device/ble.RemoteScannedDevice |
      md/ByteArray := device.data.manufacturer-data
      parseRuuvi md
Regards, Mk
f
manufacturer-specific
now takes a block. I haven't tested this, but I think you can just concatenate the company-id and data again:
Copy code
md/ByteArray := device.data.manufacturer-specific: | company-id data |
  company-id + data  // This is the result of the RHS expression.
If you only need the data, but not the company-id, you can just use that:
Copy code
md/ByteArray := device.data.manufacturer-specific: | _ data |
  data  // This is the result of the RHS expression.
m
I probably described the situation incorrectly. I receive a vector of bytes and process it if I use the 'manufacturer-data' identifier. Everything is fine. The compiler simply issues a warning that the 'manufacturer-data' identifier is deprecated and that 'manufacturer-specific' should be used instead. But if I use 'manufacturer-specific', I get a message that this method doesn't exist at all. This is the same as if I decided to change the function name 'A' to 'B' in the code, but forgot to do so in the function definition itself. When calling the function, I wrote 'B(...)' instead of 'A(...)', Iwould get the exact same error.
f
My mistake. I meant to write
manufacturer-specific
. I updated my response
m
In general, everything works, but the logic needs to be slightly modified, as it's possible to get null-value when reading data:
Copy code
start-scan :
  scan-task = task:: 
     print "BLE device '$DEVICE_NAME' monitoring has started"
     adapter.central.scan : | device/ble.RemoteScannedDevice |
       md/ByteArray? := device.data.manufacturer-specific: | company-id data | company-id + data 
       parseRuuvi md
And also need to process this possible null in the parseRuuvi function:
Copy code
parseRuuvi md/ByteArray? -> none :
  if not md :
    return
  ... & etc
Thanks anyway.