Hello verybody,
I am working on a transmission between a mobile (robot) and a ground station (laptop) using 2 photons, 1 as ‘server’ (the laptop) and the other as ‘client’ on the mobile (the robot). My purpose is to transmit a data telemetry from the robot to the laptop at high rate in WiFi through the router connected to the Internet.
In the robot, the photon (client) is connected to the sensors via I2C communication and is polling regularly the data, then fills a telemetry buffer (currently 77 bytes long). Ideally I would like to transmit more than 10 frames per second (corresponding to a serial link of 9600 bauds).
I have tried the TCP connection through the cloud with poor performance and frequent and rapid disconnections.
Now I am trying to by-pass the cloud and to use directly the WiFi connection for a TCP transmission between both photons. For this I use the Particle.disconnect() function from the Firmware API (Cloud Functions).
1- My first question is: do I need to disconnect both the server and the client from the cloud or only the server?
Once I have applied the Particle.disconnect() function (on both devices, first instruction in setup()), the leds turn green but not cyan, which looks ok as the photons are only connected to the WiFi and not to the cloud.
After a few tries it appears that sometimes one or both photons are blinking green and sometimes one or both are breathing green. I may have one blinking (the server) and the client breathing. During that time, the transmission goes on better than with the cloud connected, but still with low performance (3-5 frames per second) and sometimes disconnection where the client hangs (not blinking/breathing anymore).
2- My second question is: what should be the normal behaviour in this situation: blinking or breathing? And what is the meaning of ‘blinking’ and ‘breathing’?
3- Finally I would like to know if this transmission is optimized, or how to optimize it, or should I use a UDP connection instead to transmit faster?
Thank you very much for your support.
Here is the central code for the client:
/******************************************/
define SERVER_IP {192,168,1,10}
define SERVER_PORT 23
// Declarations, initializations...
void setup()
{
Particle.disconnect(); // Disconnect the cloud
Wire.begin(); // I2C start
/* Setup Client/Server */
byte ip[] = SERVER_IP;
client.connect(ip, SERVER_PORT);
// Initialize the sensors...
// Initialize the telemetry and I2C buffers
}
void loop()
{
// Acquisition of the sensors...
// Filling the telemetry buffer tmBuffer[]...
// Sending the telemetry buffer over WiFi
if (client.connected()) {
client.write(tmBuffer, TM_LENGTH);
client.flush();
}
else
{
}
}
Following is the central code for the server:
/************************************************/
TCPServer server = TCPServer(23);
TCPClient client;
void setup()
{
Particle.disconnect();
Serial.begin(9600); // For communication with the laptop
Serial.println();
Serial.print("Photon Server local IP: ");
Serial.println(WiFi.localIP()); // To discover the IP address of the server and type it in the client code
server.begin();
}
void loop()
{
if (client.connected()) {
while (client.available()) {
rxBuffer[rxIndex++] = client.read();
if (rxIndex == RX_BUFSIZE) {
rxIndex = 0;
Serial.write(rxBuffer, RX_BUFSIZE); // to be read by the laptop through USB line
}
}
} else {
client = server.available();
}
}