Adapter that communicates with many devices

(Lg Lindstrom) #1

I’ve created a adapter using this as a template:
https://github.com/mozilla-iot/example-adapter/blob/master/example-adapter.js

A couple of questions:
a) The adapter is not working properly for me. The console windows prints “error” but nothing more. Is it possible to turn on more extensive logging.

b) I’ve read that adapters is of (at least) two types, adapters than communicates with one device or adapters communicates with many devices. I interpreted that example above is the first kind. Is there information how to handle adapters who talks with many devices. Templates or documentation.

c) Are there documentation about how to implement Actions and Events, ??

0 Likes

(Lg Lindstrom) #2

please help … :slight_smile:

0 Likes

(Michael Stegeman) #3

An adapter can handle as many devices as it wants, there is no limitation. I’d recommend exploring our other non-trivial adapters, as you’ll find better examples there.

As for your other questions:

  1. To enable more logging, you can just use the usual console.{log,info,debug,...} functions and the output will show up in the gateway’s log.
  2. Here are some examples of actions:
  3. Here are some examples of events:
0 Likes

(Lg Lindstrom) #4

Thanks for the information. Unfortunately I am now confused, but at a much higher level :slight_smile:

  1. I am aware of logging in my code. Is it possible to turn on more logging in other modules. For example, pairing process sends a ERROR to the console. I would like to know the reason for the ERROR.

2,3) The “trivial example” exports a “load” function to the gateway and there is also pairing functions in the code. The “non-trivial” example exports a Device to the gateway. How is the pairing done then? and is it possible to add many cameras to the system?

I am aware that I am a newbee on Javascript and my question maybe is trivial if I had better knowledge about Javascript. But I still feel I am missing some basic knowledge about “use” cases and how things are expected to happen in the gateway. Is there not documentation to read? or other ways to understand how gateway, adapters, UI is supposed to work together.

Sorry if I am a “troublesome guy”, best intentions although. :slight_smile:

0 Likes

(Dave Hylands) #5

The amount and control of logging information is adapter specific. You might want to look at the Zigbee/Zwave modules for an example of run-time controllable logging. It’s pretty generic and could be used for pretty much any adapter. I should probably write up a wiki page about it.

Pairing is very adapter specific. Some adapters, like GPIO, don’t require pairing, so if you look at https://github.com/mozilla-iot/gpio-adapter/blob/master/gpio-adapter.js you’ll see that it just uses the default pairing functions: https://github.com/mozilla-iot/gateway-addon-node/blob/759200e11da2e83b67876d5fab0eaa279e7d0e2d/lib/adapter.js#L95 which don’t really do anything.

Zigbee and zwave, for example, have a much more involved pairing process.

Fundamentally, the way that new devices get added is by calling handleDeviceAdded

For simple adapters, like GPIO, the devices are determined by configuration, so the handleDeviceAdded calls are made when the adapter is loaded. Loading the adapter creates a GPIOAdapter which in turns creates a GPIODevice which calls handleDeviceAdded

For more complicated devices, handleDeviceAdded will get called through the startPairing function.

0 Likes

(Lg Lindstrom) #6

starting to feel desperat :slight_smile:

To get a more basic understanding I decided to take a couple of steps back …
Step 1.
I downloaded. https://github.com/mozilla-iot/webthing-arduino/tree/master/examples/PlatformIO/LED

It is running nicely on my ESP32 board. Using Postman I can turn a LED on and off.

Step2
I downloaded https://github.com/mozilla-iot/example-adapter and installed on my VM running gateway code.

By changing this line:

const device = new ExampleDevice(adapter, 'example-plug-2', {

to

 const device = new ExampleDevice(adapter, 'led', {

I hoped that my device should pair with the adapter but it did not.

A light bulb shows up on the “Things” page after pressing “save” and “done”.
Unfortunately the on/off button don’t seems to be connected to the device.

What is the requirement for the device and the adapter to like each other, where in the code is that check performed ?

0 Likes

(Dave Hylands) #7

I don’t think that the example adapter talks to anything.

Here’s an adapter:


that talks to this code:
https://github.com/mozilla-iot/http-on-off-wifi101 running on an MKR1000.

The place in the adapter which does the actual communication with the arduino code is here:

To talk to the EPS32 running as a webthing, you can use the thing-url-a

0 Likes