Module Xiaomi Flower Care


#101

Salut @Pti_Nico en décommentant voici les logs:

Starting Bluetooth Scan for 30 seconds !
Bluetooth Scan started
Just received 1 devices from "bluetooth" service, from Gladys. Saving them locally in RAM.
Just received 0 devices from "xiaomiht" service, from Gladys. Saving them locally in RAM.
Just received 1 devices from "miflora" service, from Gladys. Saving them locally in RAM.
Just received 0 devices from "flowerpower" service, from Gladys. Saving them locally in RAM.
Found Bluetooth peripheral, name = Flower care, id = c47c8d6a457d, address = c4:7c:8d:6a:45:7d.
Bluetooth Scan stopped
miflora - data received: {"deviceId":"c47c8d6a457d","temperature":23.4,"light":35,"moisture":2,"fertility":5}
miflora - updating batteryLevel
miflora - updating temperature
miflora - updating light
miflora - updating moisture
miflora - updating fertility
miflora - data received OK
miflora - firmware received: {"deviceId":"c47c8d6a457d","batteryLevel":99,"firmwareVersion":"3.2.1"}
miflora - firmware received OK
miflora - Error while sending batteryLevel to Gladys:
{ StatusCodeError: 400 - undefined
    at new StatusCodeError (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/home/pi/gladys-bluetooth/node_modules/request/request.js:185:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/pi/gladys-bluetooth/node_modules/request/request.js:1161:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/pi/gladys-bluetooth/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'StatusCodeError',
  statusCode: 400,
  message: '400 - undefined',
  error: undefined,
  options:
   { method: 'POST',
     uri: 'http://192.168.1.38:8080/devicestate?token=mon-token',
     body: { devicetype: 66, value: undefined },
     json: true,
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response:
   IncomingMessage {
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: true,
        ended: true,
        endEmitted: true,
        reading: false,
        sync: true,
        needReadable: false,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        destroyed: false,
        defaultEncoding: 'utf8',
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },
     readable: false,
     domain: null,
     _events:
      { end: [Array],
        close: [Array],
        data: [Function],
        error: [Function] },
     _eventsCount: 4,
     _maxListeners: undefined,
     socket:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 216,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Object],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 127,
        [Symbol(bytesRead)]: 345 },
     connection:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 216,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Object],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 127,
        [Symbol(bytesRead)]: 345 },
     httpVersionMajor: 1,
     httpVersionMinor: 1,
     httpVersion: '1.1',
     complete: true,
     headers:
      { vary: 'X-HTTP-Method-Override',
        'x-powered-by': 'Sails <sailsjs.org>',
        'set-cookie': [Array],
        date: 'Mon, 25 Feb 2019 22:06:37 GMT',
        connection: 'close',
        'transfer-encoding': 'chunked' },
     rawHeaders:
      [ 'Vary',
        'X-HTTP-Method-Override',
        'X-Powered-By',
        'Sails <sailsjs.org>',
        'set-cookie',
        'sails.sid=s%3ANjMD3a1mM9mE8Nr4BeMXZeamH4DG-eBX.2P39LII1Alc7KxQpcxCZ7VTIPDeRdNk5bJLd%2FV9Ggsw; Path=/; Expires=Tue, 12 Mar 2019 22:06:37 GMT; HttpOnly',
        'Date',
        'Mon, 25 Feb 2019 22:06:37 GMT',
        'Connection',
        'close',
        'Transfer-Encoding',
        'chunked' ],
     trailers: {},
     rawTrailers: [],
     upgrade: false,
     url: '',
     method: null,
     statusCode: 400,
     statusMessage: 'Bad Request',
     client:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 8,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 216,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        parser: null,
        _httpMessage: [Object],
        read: [Function],
        _consuming: true,
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 127,
        [Symbol(bytesRead)]: 345 },
     _consuming: true,
     _dumped: false,
     req:
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 5,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'POST /devicestate?token=mon-token HTTP/ 1.1\r\nhost: 192.168.1.38:8080\r\naccept: application/json\r\ncontent-type: application/json\r\ncontent-length: 17\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/devicestate?token=mon-token',
        _ended: true,
        res: [Circular],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        [Symbol(outHeadersKey)]: [Object] },
     request:
      Request {
        domain: null,
        _events: [Object],
        _eventsCount: 5,
        _maxListeners: undefined,
        method: 'POST',
        uri: [Object],
        body: '{"devicetype":66}',
        readable: true,
        writable: true,
        explicitMethod: true,
        _qs: [Object],
        _auth: [Object],
        _oauth: [Object],
        _multipart: [Object],
        _redirect: [Object],
        _tunnel: [Object],
        _rp_resolve: [Function],
        _rp_reject: [Function],
        _rp_promise: [Object],
        _rp_callbackOrig: undefined,
        callback: [Function],
        _rp_options: [Object],
        headers: [Object],
        setHeader: [Function],
        hasHeader: [Function],
        getHeader: [Function],
        removeHeader: [Function],
        localAddress: undefined,
        pool: {},
        dests: [],
        __isRequestRequest: true,
        _callback: [Function: RP$callback],
        proxy: null,
        tunnel: false,
        setHost: true,
        originalCookieHeader: undefined,
        _disableCookies: true,
        _jar: undefined,
        port: '8080',
        host: '192.168.1.38',
        path: '/devicestate?token=mon-token',
        _json: true,
        httpModule: [Object],
        agentClass: [Object],
        agent: [Object],
        _started: true,
        href: 'http://192.168.1.38:8080/devicestate?token=mon-token',
        req: [Object],
        ntick: true,
        response: [Circular],
        originalHost: '192.168.1.38:8080',
        originalHostHeaderName: 'host',
        responseContent: [Circular],
        _ended: true,
        _callbackCalled: true },
     toJSON: [Function: responseToJSON],
     caseless: Caseless { dict: [Object] },
     read: [Function] } }
Bluetooth Scan started
miflora - DeviceType "67" and DeviceState "temperature" inserted with success !
miflora - DeviceType "70" and DeviceState "fertility" inserted with success !
miflora - DeviceType "69" and DeviceState "moisture" inserted with success !
miflora - DeviceType "68" and DeviceState "light" inserted with success !
Stopping Bluetooth Scan for 30 seconds !
Bluetooth Scan stopped

#102

@Jean34,
Bon j’ai fait quelques corrections sur la branche ‘develop’ de mon repo github.

Tu peux l’installer et tester pour voir si tu as encore le problème?
Si c’est OK, je ferai une PR sur la version originale.


#103

Salut @Pti_Nico

voilà les logs quand je lance le setup.js:

[email protected]:~/gladys-bluetooth $ node setup.js
module.js:540
    throw err;
    ^

Error: Cannot find module 'noble'
    at Function.Module._resolveFilename (module.js:538:15)
    at Function.Module._load (module.js:468:25)
    at Module.require (module.js:587:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/pi/gladys-bluetooth/lib/scan.js:1:77)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
[email protected]:~/gladys-bluetooth $

#104

T’as oublié le npm install avant je pense


#105

pff gros nul que je suis!

@VonOx , j’ai la meme erreur en ce qui concerne la récupération de la température. mais par exemple si je clique sur le lien qu’il indique j’ai bien les valeurs dans le json…


#106

Tu as bien récupéré la branche ‘develop’ et pas fait juste un git clone du repo?

Qu’est-ce que tu entends par là?


#107

@Pti_Nico , salut, bah si j’avais simplement fait un git clone, mais vu que j’etais dans la branche develop (sur le lien que tu me donne plus haut) je pense que ça le mettrait direct , mais non, donc j’ai fait un peu de recherches et je pense avoir la bonne car là j’ai une erreur direct dans le setup.js:

[email protected]:~/gladys-bluetooth $ node setup.js
Starting Bluetooth Scan for 30 seconds !
Bluetooth Scan started
Found Bluetooth peripheral, name = Flower care, id = c47c8d6a457d, address = c4:7c:8d:6a:45:7d.
Unhandled rejection StatusCodeError: 403 - undefined
    at new StatusCodeError (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/home/pi/gladys-bluetooth/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/home/pi/gladys-bluetooth/node_modules/request/request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/home/pi/gladys-bluetooth/node_modules/request/request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/home/pi/gladys-bluetooth/node_modules/request/request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Stopping Bluetooth Scan for 30 seconds !
Bluetooth Scan stopped

#108

Une erreur 403 est lié à l’autorisation, as tu bien renseigné le fichier de config (url, token) ?


#109

@Pti_Nico Rrrr je zappe à chaque fois qu’il ne prend pas localhost mais l’ip !!!

bon j’obtiens toujours la même erreur

pour être sur que je fasse pas n’importe quoi, quand je clone le repo je fais ça :

git clone https://github.com/NickDub/gladys-bluetooth.git --branch develop --single-branch

npm install

nano config.js 

node setup.js

node app.js

#110

C’est ça.
Et lors de la modification du fichier config.js, tu renseignes l’IP de Gladys et ton token.


#111

@Pti_Nico c’est ce que j’ai fait et j’obtiens les même erreurs, tu les veux quand même ?

une capture d’écran est plus explicite je pense :slight_smile:

j’ai tout réduit mais si je développe les autres id il y a aussi des valeurs


#112

C’est ce qui est déjà stocké dans Gladys, ça :smile:

[Edit]: J’ai réussi à reproduire le problème chez moi et j’ai fait quelques corrections.
Pourrais-tu tester et me faire un retour?


#113

@Pti_Nico salut :slight_smile:

Oup’s, je comprends vraiment rien …

Bon bah ce que tu as fait a réglé mon soucis :+1:

[email protected]:~/gladys-bluetooth $ node app.js
Starting Bluetooth Scan for 30 seconds !
Bluetooth Scan started
Just received 0 devices from "xiaomiht" service, from Gladys. Saving them locally in RAM.
Just received 1 devices from "bluetooth" service, from Gladys. Saving them locally in RAM.
Just received 1 devices from "miflora" service, from Gladys. Saving them locally in RAM.
Just received 0 devices from "flowerpower" service, from Gladys. Saving them locally in RAM.
Found Bluetooth peripheral, name = Flower care, id = c47c8d6a457d, address = c4:7c:8d:6a:45:7d.
Bluetooth Scan stopped
miflora - DeviceType "83" and DeviceState "light" inserted with success !
miflora - DeviceType "82" and DeviceState "temperature" inserted with success !
miflora - DeviceType "85" and DeviceState "fertility" inserted with success !
miflora - DeviceType "84" and DeviceState "moisture" inserted with success !
miflora - DeviceType "81" and DeviceState "batteryLevel" inserted with success !
Bluetooth Scan started
[email protected]:~/gladys-bluetooth $

Tout est bon pour moi, encore un grand merci à toi pour ce module et ton aide.
Je pense en acheter 5 autres par la suite (encore 4 orchidées et une plante verte à équiper).


#114

Voilà, PR faite :

@spenceur, tu peux checker et merger?


#115

Salut, est-ce que tu as déjà vu cette api :


#116

Je ne connaissais pas, je vais jeter un œil :wink:


#117

Done :slight_smile: !