Driver questions (Maker API)

I have numerous Arduinos with various sensors. I’ve written the C++ code to push readings using GET to the hub with Maker API installed and I’ve written the corresponding driver to receive it. Everything works well.

Three questions:

  1. Is there a method to capture the incoming request in the driver? Specifically the Arduino’s IP address. If not, I can pass it as one of the parameters in the GET URL.

  2. Is there a method to capture the incoming URL and or header? Simply as a debug feature.

  3. I’m passing the secondary values (temp, humidity, etc.) in the URL separated by commas - def update(temperatureX,humidityX,pressureX). I experimented with a few methods to test for value presence and not null, but received runtime errors. I am guessing on the coding. What would be the method? The request is properly formatted on the Arduino side, but I prefer some error checking on the hub side.

I don't expect so, not through some feature in HE. Maker API receives the HTTP request and then just calls the command on the device, passing the parameters provided (if any). You are right, you could include the IP address as one of these parameters. Note that if you are wanting to maintain certain capabilities in the driver any commands from that capability that you want to modify to include the IP address would then not be compliant.

Again, I don't expect you would be able to do this through some native feature in HE / Maker API, at least within the code of the driver. You could look at turning on logging options in Maker API and see what you can get there.

When you say value presence, do you mean in what was passed to the update method? Or in terms of values that are currently stored against the device in HE, e.g. Current State attributes? Perhaps if you can provide some sample code of what you have tried so far and the error you saw, that may help paint the picture.

You don’t need to use Maker at all. In your sketch call the local IP address of your hub using port 39501 and set the HE device network ID to the hex value of your arduinos IP address. The hub will automatically call the parse function within a device matching the arduinos IP address.

You might look at @ogiewon’s awesome Hubduino library:

Within the parse function you can take the values you are sending and create events for temp, humidity, etc.

3 Likes

Why didn't I think of that....? :slightly_smiling_face:. Nice one.

2 Likes

Yes - for example, if the driver is programmed for three parameters, were three actually passed. For Maker API, sending apps/api/1198/devices/1314/update/1,2,3 has the three parameters. If 1,,3 is passed, the second parameter is apparently “absent” and from my testing generated an error when testing for =null or .isEmpty. I didn’t keep the exact code and the logs have purged the error entries.

When I first worked on the driver I used port 39501, but couldn’t get the parseLanMessage results in a usable form. I then used Maker API and I wrote a working driver surprisingly quickly. I revisited using port 39501 and was able to extract what I needed from the header parsed by parseLanMessage. I used substring to extract, but there must a better method. Anyway, the driver now supports both Maker API and port 39501.

1 Like

Choose a delimiter within your sketch and then use split() or tokenize() within the HE driver. I use a pipe | with one of my sketches and then split the string based on that character which creates a List and I iterate through it to set the various device attributes.

3 Likes