Giter VIP home page Giter VIP logo

Comments (8)

hannseman avatar hannseman commented on May 29, 2024 1

Yes you can just skip using the homebridge part of this code and use the Scanner.

const { Scanner } = require("homebridge-mi-hygrothermograph/lib/scanner");
const scanner = new Scanner();
scanner.on("temperatureChange", function (value, peripheral) {
    console.log("Temperature", value);
});

scanner.on("humidityChange", function (value, peripheral) {
    console.log("Humidity", value);
});

scanner.on("batteryChange", function (value, peripheral) {
    console.log("Battery", value);
});

Good luck!

from homebridge-mi-hygrothermograph.

muscaiu avatar muscaiu commented on May 29, 2024

Your example was great for 1 device, but right now i have a total of 4 sensors and it got pretty unstable.

This is is how the server looks right now and sometimes it's crashing and it was not hapening with 1 device.

I want to ask for a suggestionof a better way of reading from multiple devices.
Thanks!

const io = require('socket.io')();

const { Scanner } = require("homebridge-mi-hygrothermograph/lib/scanner");
const scanner = new Scanner();

io.set("origins", "*:*");

const bedroomId = '4c65a8daa726'
const kitchenId = '4c65a8dd7c37'
const vladId = '4c65a8dae1b7'
const livingId = '4c65a8dd7fc9'

io.on('connection', (client) => {
  scanner.on("temperatureChange", function (temperature, peripheral) {
    if (peripheral.id === bedroomId) {
      client.emit('temperatureBedroom', temperature)
    } else if (peripheral.id === kitchenId) {
      client.emit('temperatureKitchen', temperature)
    } else if (peripheral.id === vladId) {
      client.emit('temperatureVlad', temperature)
    } else if (peripheral.id === livingId) {
      client.emit('temperatureLiving', temperature)
    }
  });
  scanner.on("humidityChange", function (humidity, peripheral) {
    if (peripheral.id === bedroomId) {
      client.emit('humidityBedroom', humidity)
    } else if (peripheral.id === kitchenId) {
      client.emit('humidityKitchen', humidity)
    } else if (peripheral.id === vladId) {
      client.emit('humidityVlad', humidity)
    } else if (peripheral.id === livingId) {
      client.emit('humidityLiving', humidity)
    }
  });
});

const port = 4001;
io.listen(port);

from homebridge-mi-hygrothermograph.

hannseman avatar hannseman commented on May 29, 2024

Really hard to help you without you providing more information than that it's unstable and crashing. But one thing you could try is to have one Scanner per sensor i.e new Scanner(bedroomId) etc.

from homebridge-mi-hygrothermograph.

muscaiu avatar muscaiu commented on May 29, 2024

This is the error before crashing, probbaly won't help with anything:

uncaughtException: Unknown event type: 1037. 5020aa0149377cdda8654c0d040020015202
Error: Unknown event type: 1037. 5020aa0149377cdda8654c0d040020015202
    at Parser.parseEventData

I will try your example.

from homebridge-mi-hygrothermograph.

hannseman avatar hannseman commented on May 29, 2024

This error is actually a known issue: #56

Did you upgrade your system or anything like that around the time you started seeing these errors?

Also you could listen for the error-event to not crash the node-process on errors emitted by the scanner:

scanner.on("error", error =>  console.log(error));

from homebridge-mi-hygrothermograph.

muscaiu avatar muscaiu commented on May 29, 2024

I did completely reinstalled my RPi3 recently.
I am getting similar error to #56 . At first i thought it's because i use multiple sensors, but just tested and it's crashing even with 1 sensor.

Error: Unknown event type: 525. 5020aa018cc97fdda8654c0d0200ae043e26
    at Parser.parseEventData (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:174:15)
    at Parser.parse (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:56:23)
    at Scanner.parseServiceData (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:161:38)
    at Scanner.onDiscover (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:90:25)
    at Noble.emit (events.js:198:13)
    at Noble.onDiscover (/home/pi/soft/home-automation-api/node_modules/@abandonware/noble/lib/noble.js:178:10)
    at NobleBindings.emit (events.js:198:13)
    at NobleBindings.onDiscover (/home/pi/soft/home-automation-api/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:174:10)
    at Gap.emit (events.js:198:13)
    at Gap.onHciLeAdvertisingReport (/home/pi/soft/home-automation-api/node_modules/@abandonware/noble/lib/hci-socket/gap.js:256:10)
Emitted 'error' event at:
    at Scanner.parseServiceData (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:163:12)
    at Scanner.onDiscover (/home/pi/soft/home-automation-api/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:90:25)
    [... lines matching original stack trace ...]
    at Gap.onHciLeAdvertisingReport (/home/pi/soft/home-automation-api/node_modules/@abandonware/noble/lib/hci-socket/gap.js:256:10)
    at Hci.emit (events.js:198:13)
    at Hci.processLeAdvertisingReport (/home/pi/soft/home-automation-api/node_modules/@abandonware/noble/lib/hci-socket/hci.js:651:10)

The on error event doesn't help. It works for a while ..like minutes ..and then i'm seeing the error message and the app crashes.

 bedroomScanner.on("error", error => console.log(error));

from homebridge-mi-hygrothermograph.

muscaiu avatar muscaiu commented on May 29, 2024

Hmmm decided to give this another try, and now in version 2.3.2 it's not crashing anymore ...at least not yet! :D

Keep up the good work!

from homebridge-mi-hygrothermograph.

muscaiu avatar muscaiu commented on May 29, 2024

I was wrong. It's still throwing the same error.
I posted a new issue #85

from homebridge-mi-hygrothermograph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.