nikita-leonov / particleio-homekit

Experiment to show how to glue together Particle.io and HomeKit through HomeBridge server.
MIT License
78 stars 13 forks source link

Question about your want to improve on homebride-HTTP #2

Open temeyers opened 8 years ago

temeyers commented 8 years ago

okay so here is the commands i need to commit on or off using curl for my living room lamp however i changed my access token so it wont work for everyone to see i changed one digit to break it if i can get this figured out then the homebridge-http is all i need !

however in config.json there is a on_body and an off_body and thats where i am stuck as you can see ... the homebridge fires up and siri works also my appletv saw the homebridge and made it available on and off of wifi which is great news in itself... can you help me out with the on_body and off_body please ! i have tried everything i can think off for 2 days !

This is the curl command i use turn on my lamp: ​ curl https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26293 -d params=D2,HIGH

this is the curl command i use to turn off my lamp curl https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26293 -d params=D2,LOW

this is just part of the accessories section of my config.json

accessories": [ { "accessory": "Http", "name": "Kitchen Lamp", "on_url": "https://api.particle.io/v1/devices/53ff6$ "on_body": "{\"D2, HIGH\"}", "off_url": "https://api.particle.io/v1/devices/53ff$ "off_body": "{\"D2, LOW\"}", "brightness_url": "https://192.168.1.22:3030/device$ "username": "", "password": "", "sendimmediately": "",

nikita-leonov commented 8 years ago

The current implementation of particleio-homekit is highly desynchronized with a latest revision of homebridge. Latest revision does not have generic http device anymore. Meanwhile I do not see on_body and off_body parameters in the older Http.js implementation — https://github.com/nfarina/homebridge/blob/3da52388e874e94fda69a35ecd039b595761bd56/accessories/Http.js

Answer to your question will highly depend on what revision of home bridge you will use. What revision do you use?

ps I likely need to update README.md to emphasis this project is not in active development now.

temeyers commented 8 years ago

I use the current homebridge and I installed npm install homebridge-http ... It comes with a sample-configure.json and in it ... It has the on_body and off_body ... Everything is working but it's giving a -1 return and not changing the device state ... The particle photon is running basic tinker code so that all I have to do is send the digitalwrite high or low to change the state ... The only issue is that my URL is friendly to curl and doesn't work in the URL line ... Meaning I have to take the -d Params=D2, HIGH and place that part of it within the on_body and the off_body but I don't seem to understand how to type it out correctly but I am open to any work around ...

temeyers commented 8 years ago

Configure.json lol config.json ignore all the type errors this phone sucks

nikita-leonov commented 8 years ago

Since body is passed as form data you need to specify not only key data but values too. In your case it should be like following:

"on_body": "{\"params\":\"D2, HIGH\"}"

I think it should help. I actually not familiar with homebridge-http specific, so you may get better answer from homebridge-http developers directly in their repo. :)

temeyers commented 8 years ago

I will try this nearly immediately ... If it works how do I buy you a beer

temeyers commented 8 years ago

well that didnt seem to make any difference its output is as follows but if i can get this to work then there is a valid solution for the time being for particle

Homebridge is running on port 51826. [Kitchen Lamp] Setting power state to on [Kitchen Lamp] HTTP power function succeeded! [Kitchen Lamp] IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: true, reading: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _events: { end: [ [Function: responseOnEnd], [Function], [Function], [Function] ], close: [ [Function], [Function] ], data: [Function], error: [Function] }, _eventsCount: 4, _maxListeners: undefined, socket: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: undefined, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 204, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 204, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 21\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, connection: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: undefined, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 204, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 204, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 21\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, idleTimeout: -1 }, httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: { server: 'nginx/1.6.2', date: 'Thu, 03 Dec 2015 03:35:50 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '' }, rawHeaders: [ 'Server', 'nginx/1.6.2', 'Date', 'Thu, 03 Dec 2015 03:35:50 GMT', 'Content-Type', 'application/json; charset=utf-8', 'Content-Length', '99', 'Connection', 'close', 'X-Powered-By', 'Express', 'Access-Control-Allow-Origin', '_' ], trailers: {}, rawTrailers: [], upgrade: false, url: '', method: null, statusCode: 200, statusMessage: 'OK', client: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: undefined, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 204, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 204, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 21\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, _consuming: true, _dumped: false, req: ClientRequest { domain: null, _events: { socket: [Object], response: [Function: bound ], error: [Function: bound ], drain: [Function] }, _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 204, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: { 'content-length': false }, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: [Object], readable: false, domain: null, _maxListeners: 0, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 204, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, connection: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: [Object], readable: false, domain: null, _maxListeners: 0, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 204, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 21\r\nConnection: close\r\n\r\n', _headers: { host: 'api.particle.io', 'content-length': 21 }, _headerNames: { host: 'host', 'content-length': 'content-length' }, _onPendingData: null, agent: Agent { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object], requests: {}, sockets: [Object], freeSockets: {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, maxCachedSessions: 100, _sessionCache: [Object] }, socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, request: Request { domain: null, _events: { error: [Function: bound ], complete: [Function: bound ], pipe: [Function], end: [Object], data: [Function] }, _eventsCount: 5, _maxListeners: undefined, callback: [Function], method: 'POST', body: '{"params":"D2, HIGH"}', readable: true, writable: true, explicitMethod: true, _qs: Querystring { request: [Circular], lib: [Object], useQuerystring: undefined, parseOptions: {}, stringifyOptions: {} }, _auth: Auth { request: [Circular], hasAuth: true, sentAuth: false, bearerToken: null, user: '', pass: '' }, _oauth: OAuth { request: [Circular], params: null }, _multipart: Multipart { request: [Circular], boundary: '6b0a4f9b-e796-401a-8983-2538924b908c', chunked: false, body: null }, _redirect: Redirect { request: [Circular], followRedirect: true, followRedirects: true, followAllRedirects: false, allowRedirect: [Function], maxRedirects: 10, redirects: [], redirectsFollowed: 0, removeRefererHeader: false }, _tunnel: Tunnel { request: [Circular], proxyHeaderWhiteList: [Object], proxyHeaderExclusiveList: [] }, headers: { 'content-length': 21 }, setHeader: [Function], hasHeader: [Function], getHeader: [Function], removeHeader: [Function], localAddress: undefined, pool: {}, dests: [], __isRequestRequest: true, _callback: [Function], uri: Url { protocol: 'https:', slashes: true, auth: null, host: 'api.particle.io', port: 443, hostname: 'api.particle.io', hash: null, search: '?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', query: 'access_token=7458609c672644bb8d29780fbe60a71f3ce26292', pathname: '/v1/devices/53ff6d066667574813461267/digitalwrite', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', href: 'https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292' }, proxy: null, tunnel: true, setHost: true, originalCookieHeader: undefined, _disableCookies: true, _jar: undefined, port: 443, host: 'api.particle.io', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?accesstoken=7458609c672644bb8d29780fbe60a71f3ce26292', httpModule: { Server: [Object], createServer: [Function], globalAgent: [Object], Agent: [Object], request: [Function], get: [Function] }, agentClass: { [Function: Agent] super: [Object] }, agent: Agent { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object], requests: {}, sockets: [Object], freeSockets: {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, maxCachedSessions: 100, _sessionCache: [Object] }, _started: true, href: 'https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', req: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 204, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Object], connection: [Object], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 21\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, ntick: true, response: [Circular], originalHost: 'api.particle.io', originalHostHeaderName: 'host', responseContent: [Circular], _destdata: true, _ended: true, callbackCalled: true }, toJSON: [Function: responseToJSON], caseless: Caseless { dict: { server: 'nginx/1.6.2', date: 'Thu, 03 Dec 2015 03:35:50 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '' } }, read: [Function], body: '{\n "id": "53ff6d066667574813461267",\n "last_app": "",\n "connected": true,\n "return_value": -1\n}' } [Kitchen Lamp] { "id": "53ff6d066667574813461267", "last_app": "", "connected": true, "return_value": -1 } [Kitchen Lamp] Setting power state to off [Kitchen Lamp] HTTP power function succeeded! [Kitchen Lamp] IncomingMessage { _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: true, reading: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _events: { end: [ [Function: responseOnEnd], [Function], [Function], [Function] ], close: [ [Function], [Function] ], data: [Function], error: [Function] }, _eventsCount: 4, _maxListeners: undefined, socket: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: <Buffer 30 82 06 83 02 01 01 02 02 03 03 04 02 c0 2f 04 20 2e 53 2c ab 38 52 9c d7 02 23 1c dd 95 a8 46 89 55 2a 35 c4 ec 5c 69 5c 23 38 54 c8 17 0a 45 07 04 ... >, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 203, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 203, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 20\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, connection: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: <Buffer 30 82 06 83 02 01 01 02 02 03 03 04 02 c0 2f 04 20 2e 53 2c ab 38 52 9c d7 02 23 1c dd 95 a8 46 89 55 2a 35 c4 ec 5c 69 5c 23 38 54 c8 17 0a 45 07 04 ... >, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 203, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 203, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 20\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, idleTimeout: -1 }, httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: { server: 'nginx/1.6.2', date: 'Thu, 03 Dec 2015 03:35:56 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '' }, rawHeaders: [ 'Server', 'nginx/1.6.2', 'Date', 'Thu, 03 Dec 2015 03:35:56 GMT', 'Content-Type', 'application/json; charset=utf-8', 'Content-Length', '99', 'Connection', 'close', 'X-Powered-By', 'Express', 'Access-Control-Allow-Origin', '*' ], trailers: {}, rawTrailers: [], upgrade: false, url: '', method: null, statusCode: 200, statusMessage: 'OK', client: TLSSocket { _tlsOptions: { pipe: null, secureContext: [Object], isServer: false, requestCert: true, rejectUnauthorized: true, session: <Buffer 30 82 06 83 02 01 01 02 02 03 03 04 02 c0 2f 04 20 2e 53 2c ab 38 52 9c d7 02 23 1c dd 95 a8 46 89 55 2a 35 c4 ec 5c 69 5c 23 38 54 c8 17 0a 45 07 04 ... >, NPNProtocols: undefined, requestOCSP: undefined }, _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: { close: [Object], end: [Object], finish: [Function: onSocketFinish], _socketEnd: [Function: onSocketEnd], secure: [Function], free: [Function: onFree], agentRemove: [Function: onRemove], drain: [Function: ondrain], error: [Object] }, _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null, resumeScheduled: false }, readable: false, domain: null, _maxListeners: 0, _writableState: WritableState { objectMode: false, highWaterMark: 16384, needDrain: false, ending: true, ended: true, finished: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: true, errorEmitted: false }, writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 203, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: TLSWrap { _externalStream: {}, fd: -22, _parent: [Object], _parentWrap: undefined, _secureContext: [Object], reading: true, owner: [Circular], onread: [Function: noop], writeQueueSize: 1, onhandshakestart: [Function], onhandshakedone: [Function: bound ], onocspresponse: [Function: bound onocspresponse], onerror: [Function] }, server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 203, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Circular], connection: [Circular], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 20\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, _consuming: true, _dumped: false, req: ClientRequest { domain: null, _events: { socket: [Object], response: [Function: bound ], error: [Function: bound ], drain: [Function] }, _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 203, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: { 'content-length': false }, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: [Object], readable: false, domain: null, _maxListeners: 0, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 203, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, connection: TLSSocket { _tlsOptions: [Object], _secureEstablished: true, _securePending: false, _newSessionPending: false, _controlReleased: true, _SNICallback: null, servername: null, npnProtocol: undefined, authorized: true, authorizationError: null, encrypted: true, _events: [Object], _eventsCount: 9, _connecting: false, _hadError: false, _handle: null, _parent: null, _host: 'api.particle.io', _readableState: [Object], readable: false, domain: null, _maxListeners: 0, _writableState: [Object], writable: false, allowHalfOpen: false, destroyed: true, bytesRead: 317, _bytesDispatched: 203, _sockname: null, _pendingData: null, _pendingEncoding: '', ssl: [Object], server: undefined, _requestCert: true, _rejectUnauthorized: true, parser: null, _httpMessage: [Circular], read: [Function], _consuming: true, _idleNext: null, _idlePrev: null, _idleTimeout: -1 }, _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 20\r\nConnection: close\r\n\r\n', _headers: { host: 'api.particle.io', 'content-length': 20 }, _headerNames: { host: 'host', 'content-length': 'content-length' }, _onPendingData: null, agent: Agent { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object], requests: {}, sockets: [Object], freeSockets: {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, maxCachedSessions: 100, _sessionCache: [Object] }, socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, request: Request { domain: null, _events: { error: [Function: bound ], complete: [Function: bound ], pipe: [Function], end: [Object], data: [Function] }, _eventsCount: 5, _maxListeners: undefined, callback: [Function], method: 'POST', body: '{"params":"D2, LOW"}', readable: true, writable: true, explicitMethod: true, _qs: Querystring { request: [Circular], lib: [Object], useQuerystring: undefined, parseOptions: {}, stringifyOptions: {} }, _auth: Auth { request: [Circular], hasAuth: true, sentAuth: false, bearerToken: null, user: '', pass: '' }, _oauth: OAuth { request: [Circular], params: null }, _multipart: Multipart { request: [Circular], boundary: '38e928b5-e43b-426e-a8e9-669163c562b6', chunked: false, body: null }, _redirect: Redirect { request: [Circular], followRedirect: true, followRedirects: true, followAllRedirects: false, allowRedirect: [Function], maxRedirects: 10, redirects: [], redirectsFollowed: 0, removeRefererHeader: false }, _tunnel: Tunnel { request: [Circular], proxyHeaderWhiteList: [Object], proxyHeaderExclusiveList: [] }, headers: { 'content-length': 20 }, setHeader: [Function], hasHeader: [Function], getHeader: [Function], removeHeader: [Function], localAddress: undefined, pool: {}, dests: [], __isRequestRequest: true, _callback: [Function], uri: Url { protocol: 'https:', slashes: true, auth: null, host: 'api.particle.io', port: 443, hostname: 'api.particle.io', hash: null, search: '?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', query: 'access_token=7458609c672644bb8d29780fbe60a71f3ce26292', pathname: '/v1/devices/53ff6d066667574813461267/digitalwrite', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', href: 'https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292' }, proxy: null, tunnel: true, setHost: true, originalCookieHeader: undefined, _disableCookies: true, _jar: undefined, port: 443, host: 'api.particle.io', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?accesstoken=7458609c672644bb8d29780fbe60a71f3ce26292', httpModule: { Server: [Object], createServer: [Function], globalAgent: [Object], Agent: [Object], request: [Function], get: [Function] }, agentClass: { [Function: Agent] super: [Object] }, agent: Agent { domain: null, _events: [Object], _eventsCount: 1, _maxListeners: undefined, defaultPort: 443, protocol: 'https:', options: [Object], requests: {}, sockets: [Object], freeSockets: {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, maxCachedSessions: 100, _sessionCache: [Object] }, _started: true, href: 'https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', req: ClientRequest { domain: null, _events: [Object], _eventsCount: 4, _maxListeners: undefined, output: [], outputEncodings: [], outputCallbacks: [], outputSize: 203, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedHeader: [Object], _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [Object], connection: [Object], _header: 'POST /v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292 HTTP/1.1\r\nhost: api.particle.io\r\ncontent-length: 20\r\nConnection: close\r\n\r\n', _headers: [Object], _headerNames: [Object], _onPendingData: null, agent: [Object], socketPath: undefined, method: 'POST', path: '/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292', parser: null, res: [Circular] }, ntick: true, response: [Circular], originalHost: 'api.particle.io', originalHostHeaderName: 'host', responseContent: [Circular], _destdata: true, _ended: true, _callbackCalled: true }, toJSON: [Function: responseToJSON], caseless: Caseless { dict: { server: 'nginx/1.6.2', date: 'Thu, 03 Dec 2015 03:35:56 GMT', 'content-type': 'application/json; charset=utf-8', 'content-length': '99', connection: 'close', 'x-powered-by': 'Express', 'access-control-allow-origin': '*' } }, read: [Function], body: '{\n "id": "53ff6d066667574813461267",\n "last_app": "",\n "connected": true,\n "return_value": -1\n}' } [Kitchen Lamp] { "id": "53ff6d066667574813461267", "last_app": "", "connected": true, "return_value": -1 }

temeyers commented 8 years ago

heres my full config.json

{ "bridge": { "name": "HomebridgePI", "username": "CD:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-156" },

        "description": "The Onion!",

        "platforms": [],

        "accessories": [
            {
                "accessory": "Http",
                "name": "Kitchen Lamp",
                "on_url": "https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292",
                "on_body": "{\"params\":\"D2, HIGH\"}",
                "off_url": "https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite?access_token=7458609c672644bb8d29780fbe60a71f3ce26292",
                "off_body": "{\"params\":\"D2, LOW\"}",
                "brightness_url": "https://192.168.1.22:3030/devices/23222/brightness/%b",
                            "username": "",
                            "password": "",
                            "sendimmediately": "",
                "http_method": "POST",
                "http_brightness_method": "POST",
                            "service": "Switch",
                            "brightnessHandling": "no"
            }
        ]
    }
nikita-leonov commented 8 years ago

I traced request curl --trace-ascii - --url https://api.particle.io/v1/devices/53ff6d066667574813461267/digitalwrite\?access_token\=7458609c672644bb8d29780fbe60a71f3ce26293 -d params=D2,HIGH and found that it is actually send it as raw data. So body should be params=D2,HIGH, so based on an output that you provided following config change should be enough:

"on_body": "params=D2, HIGH"
cmegens commented 8 years ago

But where in this whole story does your access token go?

I'll explain my situation: I have rolling shutters on some of my windows at home. They are electric and come with a remote. In order to open and close them anywhere, I ordered an extra remote and connected a particle photon to the remote with some transistors. This way, my rolling shutters are connected to the cloud. Now, here is the main issue: in order to close the shutters I have to press the down button on the remote, but then also release again. Simulating a short, nice button press. Therefore, I created 2 functions that do just that, a 1 sec press on the up button (function called open) and a 1 second button press on the down button (function called close). This also allowed me to create a third function; semiclose. Here the shutters close but stop near the end, leaving room and gaps in between the shutters for air to pass through. Here I just timed the whole thing and after 15 seconds I give the stop command. So function semiclose = D1(connected to down button) High, 1sec, D1 Low, 15 sec, D2 (connected to stop button) High, 1 sec, D2 Low.

Now, with homebridge I would like to call these functions, instead of just digital writes to the pins. That means a difference between saying: "Hey Siri, please close the shutters" or "Hey Siri, turn on particle device 1". "Hey siri, turn off particle device 1"

Now, to me this sounds like it's better to use the http plugin then the particle, since the particle plugin only allows me to do the second one, right? Plus, I have no idea where to put Particle.js on my raspberry.

With Http plugin I can actually go to the specific url of my different functions, and name them as such. But shouldn't I also have a access token somewhere? This curl command in terminal works (with my access token and device ID):

curl https://api.particle.io/v1/devices/123456789/open\?access_token\=123456789 -d params=semiclose

But how do I put this into the http plugin?

nikita-leonov commented 8 years ago

@cmegens here is an issue where discussed similar problem — https://github.com/nfarina/homebridge/issues/69 if you alternate ParticleAccessory.js with a property accessory type you should be able to control your device with "turn on" "turn off" but other specific to shutters types of commands. As for an access token in my proof of concept I have it in config and used it to build URLs in ParticleAccessory.js.

cmegens commented 8 years ago

Ah ok, I'll try the updated index.js then, as I'm running the latest version of homebridge! I'll let you know if this works. Thanks for the great work on this!