Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE Characteristic gives an error: Cannot read property '....' of undefined #11

Closed
koktaildotcom opened this issue Dec 13, 2018 · 23 comments
Assignees

Comments

@koktaildotcom
Copy link

koktaildotcom commented Dec 13, 2018

I did a rewrite for the app com.mi.flora that can read out sensor information from the xiaomi mi flora devices. It all works fine except for the second (and all other) timeout to read sensor information again.

I've searched for hours through my code but it looks something in core. The second time i want the sensors to read (i've disconnected the BlePeripheral correctly the first time) i cannot call write to the characteristic.

{ Error: Cannot read property '00001a0000001000800000805f9b34fb' of undefined 
   at Object.JSON.parse (/opt/homey-client/system/helpers/jsonfns.js:1:1190) 
   at JSON.parse (<anonymous>) 
   at jsonToObject (/opt/homey-client/system/helpers/jsonfns.js:1:1083) 
   at function.e.data.map.e (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1379) 
   at Array.map (<anonymous>) 
   at HomeyClient._onMessage (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1372) 
   at emitTwo (events.js:126:13) 
   at process.emit (events.js:214:7) 
   at emit (internal/child_process.js:762:12) 
   at _combinedTickCallback (internal/process/next_tick.js:142:11) 
 message: 'Cannot read property \'00001a0000001000800000805f9b34fb\' of undefined' } 
update device Philodendron erubescens 
(node:30900) UnhandledPromiseRejectionWarning: Error: Error: TypeError: Cannot read property 'read' of undefined 
   at /lib/MiFloraDriver.js:335:39 
   at <anonymous> 
   at process._tickCallback (internal/process/next_tick.js:189:7)
@koktaildotcom
Copy link
Author

koktaildotcom commented Dec 13, 2018

Can this be related to: #7 ?

@WeeJeWel
Copy link

What ID is 00001a0000001000800000805f9b34fb. Characteristic, service, etc?

@koktaildotcom
Copy link
Author

koktaildotcom commented Dec 14, 2018

Thats the data write characteristic.

@koktaildotcom
Copy link
Author

If you have a 'xiaomi mi flora' device you can try this branch: https://github.com/koktaildotcom/homey-mi-flora/tree/feature/v2-rewrite?files=1

It accur the second time the sensor is read.

@koktaildotcom
Copy link
Author

I've tried the branch on rc3 with all devices removed. Thought there could be a difference. But the same error occur.

@koktaildotcom
Copy link
Author

koktaildotcom commented Dec 17, 2018

Still an issue on rc4

@koktaildotcom
Copy link
Author

Still an issue with rc7

@koktaildotcom
Copy link
Author

@WeeJeWel any idea when you can take a look at this issue?

koktaildotcom added a commit to koktaildotcom/homey-mi-flora that referenced this issue Jan 11, 2019
  * trigger flows static thought the app (best practice 2.0)
  * rewrite the update sequence part for better performance
  * try to resolve issue with bug athombv/homey-apps-sdk-issues#11
  * try to resolve issue with bug athombv/homey-apps-sdk-issues#7
  * fixed typo bug `true` => `this` in the `Homey.FlowCardTriggerDevice`
@koktaildotcom
Copy link
Author

Still an issue with 2.0.0

@koktaildotcom
Copy link
Author

The issue is verified by multiple alpha users.

@WeeJeWel
Copy link

We will address this issue in a 2.x release. Sorry for the delay!

@gerrit1968
Copy link

We will address this issue in a 2.x release. Sorry for the delay!

@WeeJeWel any idea when the problem with the BLE will be solved?

@WeeJeWel
Copy link

This issue has been resolved in Homey v2.0.5. Thank you for reporting!

@koktaildotcom
Copy link
Author

This is still an issue on Homey v2.0.5

@WeeJeWel WeeJeWel reopened this Mar 4, 2019
@koktaildotcom
Copy link
Author

Sorry, wrong issue.

@koktaildotcom
Copy link
Author

This issue: #7 is still a problem

@koktaildotcom
Copy link
Author

koktaildotcom commented Mar 4, 2019

Now i encounter this issue on Homey v2.0.5 (after PTP and reboot twice)

The log "already in realtime mode" is a test log to don't break on the error but notify that the service is cached and already in realtime mode. Can this be the problem? I can imagine that if you store an service in cache the state is static. But the BLE service of the Mi Flora is changed because you need to set the device in a 'real time data' state to be able to read data from the device.

return service.write(REALTIME_CHARACTERISTIC_UUID, Buffer.from([0xA0, 0x1F]), false).then(() => {
                        return service;
                    }).catch((error) => {
                        console.log(' ----- already in realtime mode!');
                        console.log(error);
                        return service;
                    });

Gives an error:

 ----- already in realtime mode!
{ Error: Cannot read property '00001a0000001000800000805f9b34fb' of undefined
    at Object.JSON.parse (/opt/homey-client/system/helpers/jsonfns.js:1:1190)
    at JSON.parse (<anonymous>)
    at jsonToObject (/opt/homey-client/system/helpers/jsonfns.js:1:1083)
    at function.e.data.map.e (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1379)
    at Array.map (<anonymous>)
    at HomeyClient._onMessage (/opt/homey-client/system/manager/ManagerApps/bootstrap/sdk/v2/lib/HomeyClient.js:1:1372)
    at emitTwo (events.js:126:13)
    at process.emit (events.js:214:7)
    at emit (internal/child_process.js:762:12)
    at _combinedTickCallback (internal/process/next_tick.js:142:11)
  message: 'Cannot read property \'00001a0000001000800000805f9b34fb\' of undefined' }

@koktaildotcom koktaildotcom reopened this Mar 6, 2019
@koktaildotcom
Copy link
Author

I've been searching for a sollution for hours yesterday, but i've always get this exact error. I've tried to change the strategy into the 'foreach characteristic`.

It looks like internally the service is saved but the service of the device is changed. The first iteration of the update sequence works 100% of the time. The seconds one fails 100% of the time.

Can you have a look at the core if you run the branch: https://github.com/koktaildotcom/homey-mi-flora/tree/feature/v2-rewrite?files=1?

@koktaildotcom
Copy link
Author

return service.write(REALTIME_CHARACTERISTIC_UUID, Buffer.from([0xA0, 0x1F]), false).then(() => {
                        return service;
                    }).catch((error) => {
                        console.log(' ----- already in realtime mode!');
                        console.log(error);
                        return service;
                    });

At this point the service is a data service from the discovery. The realtime characteristic cannot be found on the object once it is stored internally so it looks to me.

@koktaildotcom
Copy link
Author

Looks related to: #73

@WeeJeWel
Copy link

WeeJeWel commented Mar 8, 2019

I cannot seem to reproduce the issue. Could you please point me to a branch of your repository where this does occur?

@koktaildotcom
Copy link
Author

koktaildotcom commented Mar 8, 2019

  1. Checkout: https://github.com/koktaildotcom/homey-mi-flora/tree/feature/v2-rewrite?files=1 and run the code.
  2. Add a new device (or use an existing)
  3. Wait until the second iteration kicks in, this is the point the error occur.

In lib/MiFloraDriver.js you van change the update interval (search for interval)

@WeeJeWel
Copy link

Fixed in v2.1.2-rc.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants