ni-c / heimcontrol.js

Home-Automation with node.js and Raspberry PI
MIT License
1.41k stars 297 forks source link

API for Arduino Module #54

Closed JorisM closed 10 years ago

JorisM commented 10 years ago

I want to extend the android app to support the rc-switch.

Currently, the route for api requests is set as follows: 157 app.all('/api/:plugin/:method?', Routes.isAuthorized, Routes.api, Routes.notFound);

This works for example for the GPIO plugin, because the route would be api/gpio/get or similar. Now for Arduino Plugins, I also need to pass the which of the three methods (arduino-rcswitch, arduino-irremote, arduino-led).

How would you go about passing that data? Add another route? Or just pass the method as a parameter in the json object?

ni-c commented 10 years ago

I would pass the method as a parameter in the JSON POST data and switch them in the api function.

There is something similar in the socket-part of the Arduino-Plugin:

app.get('sockets').on('connection', function(socket) {
  // Arduino toggle
  socket.on('arduino-rcswitch', function(data) {
    that.rcswitch(data);
  });
  // Arduino toggle
  socket.on('arduino-irremote', function(data) {
    that.irremote(data);
  });
  // Arduino toggle
  socket.on('arduino-led', function(data) {
    that.led(data);
  });
});

The labels i currently use are:

JorisM commented 10 years ago

Thanks!