So... you like Yoctopuce devices a lot: you installed many of them everywhere and connected them to a few Raspberry Pi on which a VirtualHub is running. That's great, thank you for your confidence. There is a weird thing though: you cannot manage to write a Yoctopuce program able to contact two Raspberry Pi at the same time..
Each time you call YAPI.RegisterHub() with one of your raspberry Pi address, devices detected on a previously registered raspberry PI mysteriously disappear. Well, actually, this is not caused by a limitation of the Yoctopuce API, this is caused by a petty configuration error.
Yoctopuce API inner working
To make sure it can identify any device without ambiguity, the Yoctopuce API uses a features present in all of Yoctopuce devices: an unique serial number. No matter the method you use in your code to find a Yoctopuce device, the API will always convert it to the device's serial number and use it to communicate with the device. Since serial numbers are assigned at factory and since they are read-only, one can be sure they are always unique and no addressing conflict can appear. These is one little exception though.
VirtualHub serial number
The VirtualHub application is basically a software version of the YoctoHubs, unless the YoctoHubs are an hardware version of the VirtualHub, we are not sure anymore. Anyway, if one wants the VirtualHub to work properly with the Yoctopuce API, a VirtualHub must have a proper serial number like all Yoctopuce devices. That's why, each time the VirtualHubis is started, it dynamically generates a serial number based on the host's network name , aka the hostname.
The VirtualHub serial number, generated from the host network name.
RegisterHub and Raspberry Pi
Most of the time this works pretty fine, but a small problem might occur on computers installed from a pre-configured monolithic image. Raspberry PI are a typical example. Quite obviously, computer installed from the same image will end up with the same settings, including the same hostname. Because of the way serial number are generated, VirtualHub running on machines with the same hostname will end up with the same serial number. This is no good.
When one makes a registerHub() call on a first machine , the API will contact the VirtualHub running on the said machine, ask for many information including serial numbers and a list of all Yoctopuce devices connected on the machine. Then it will store all that information in memory using the serial numbers as an index key. Then when one makes a second registerHub() call on a second machine with the same hostname, the API will contact the second VirtualHub, ask for its serial number, figure out that it already knows that serial number and it will mistake it for the first VirtualHub. Then it will notice that the devices found during the first contact are not listed anymore, so it will assume they are not connected anymore. Hence their disappearance for the API device list.
How to fix the problem
The fix is dead simple: make sure that all your machines connected to the same subnet have an unique hostname. Don't forget: hostnames are supposed to be unique. Doing otherwise is a nice way to create head scratching network problems .