The most experienced Yoctopuce module users know that they all host a mini web server that enables you to control them. Usually, we use the Yoctopuce library to communicate with the modules, but it is sometimes useful to directly use HTTP requests to drive the Yoctopuce modules. Today, we're sharing some secrets about this feature.
Documented use
In the user's guide of each Yoctopuce module, there is a chapter titled Using with unsupported languages. One of the solutions proposed consists precisely in using HTTP requests, sent to the module through a VirtualHub or a YoctoHub-Ethernet.
To test this feature, use the "Open API Browser" link available at the bottom of your module interface window, with a web browser:
Link to open the REST interface
In the window that opens, you can modify each attribute of the module, using first the edit button and then the apply button to apply the changes:
Manually changing an attribute
After you have performed a modification, if you go to the very bottom of the page, you can see the HTTP request which was sent to apply the requested modification:
Corresponding HTTP request
You can thus easily discover how to access the essential functions of our modules with HTTP requests: it's the whole interest of the REST interface, of which the use is normally self-explanatory. If the semantics of an attribute escapes you, you can always find explanations in the module user's guide.
And undocumented use...
On top of the use to access Yoctopuce modules from an unsupported language, you can sometimes have an interest in using the REST interface in a somewhat specific case: to override the fact that our programming library doesn't allow you to access Yoctopuce modules connected to a YoctoHub through its USB connection.
Let's start by explaining the limitation: the USB link with a YoctoHub has a very limited bandwidth. Moreover, for reasons linked to the protocol, it supports only one request at a time. If our library allowed you to talk to all the modules behind a YoctoHub connected by USB, users would risk finding themselves in a situation where one request is blocked or delayed because another request on another module has not ended. The result would be a slow to react interface which wouldn't be fully predictable. We therefore opted in favor of quality of service and imposed the use of the network channel, much more flexible, to communicate with sub-modules.
But if you find yourself in a specific case where it's quite impossible to use the network, you can in fact work around this limitation by using the REST interface. To do so, start by opening the REST interface of the YoctoHub itself, as it is the only one appearing in the VirtualHub, and look for the section titled whitePages:
The whitePages section of the REST API
There, there is an entry for the hub itself, but also an entry for each module connected to the hub. If you click on the Open API Browser button, a new window opens enabling you to drive the module through its REST API, through the USB link and the YoctoHub.
If you have a look at the corresponding HTTP requests at the bottom of the page, you can see that the secret consists in cascading the serial numbers of the YoctoHub and of the module in the URL:
Calling the REST API through a YoctoHub
Now you know that if you really need it, you can communicate by USB with a Yoctopuce module behind a YoctoHub. But if you use this feature, which is at the very limit of what we support, don't forget that you use a communication channel usually reserved to the hub. And if you encounter a limitation due to the competition between two requests, we can only tell you that we warned you about the problem...