Hi,
I need to send a sensor value (so not big amount of data but more frequently) to my iPhone (SE) every 100 ms… I was not sure with how much delay it is possible, and I did not find any test about it. So I did myself, and share it with you guys, maybe somebody needs it also.
Test method:
I send the current millis of the photon to iphone, and the iphone sends back the value it has received.
If the photon got back the message, it prints out the current millis (received time), and the received msg (which is the current millis at the time when the photon has sent). So the differences shows, that how much time to send the sensor value to iphone, and receive it back.
I have tested with 20 ms sending interval, and my findings show that:
it takes around 3-5 ms to send and receive back the short msg between photon and iPhone SE
My code was:
TCPClient client;
byte server[] = { 192, 168, 1, 102 };
bool client_connected = false;
unsigned long last_send = 0;
unsigned long last_connection_try = 0;
unsigned long last_blink = 0;
int blink_interval = 100;
int led = D7;
bool blink_state = LOW;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(115200);
// Wait for a USB serial connection for up to 30 seconds
//waitFor(Serial.isConnected, 30000);
connectToServer();
Particle.publish("device starting");
client.setTimeout(1);
}
void connectToServer() {
if (millis()-last_connection_try > 6000) {
Serial.println("connecting...");
last_connection_try = millis();
if (client.connect(server, 3456)) {
Serial.println("Connected");
client_connected = true;
} else{
Serial.println("connection failed");
}
Serial.println(millis() - last_connection_try);
}
}
void loop() {
if (!client.connected()) {
if (client_connected == true) {
Serial.println("disconnecting.");
client.stop();
client_connected = false;
}
connectToServer();
}
if (client.available()) {
Serial.printf("client - %i: ", millis());
delay(10);
while (client.available()) {
Serial.write(client.read());
}
Serial.println();
}
if (millis() - last_send >= 20) {
last_send = millis();
if (client.connected()) client.print(millis());
}
if (millis() - last_blink > blink_interval) {
last_blink = millis();
blink_state = !blink_state;
digitalWrite(led, blink_state);
}
}
Attached the logged files.