On my computer I have tcp server running , I ensure using the netstat command:
$ netstat -vanp tcp | grep 7138
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 192.168.5.165:7138 0.0.0.0:* LISTEN -
and in my particle photon
TCPClient client;
String tcp_serer_ip = "192.168.5.165";
int serverPort = 7138;
client.connect(tcp_serer_ip, serverPort);
if (client.connected()) {
char data[256];
// Prepare a buffer with JSON data
snprintf(data, sizeof(data), "{\"device\":\"photon\",\"temp\":%.2f,\"height\":%.2f,\"pressure\":%.2f}", cTemp, height, pressure);
// Send to the server. Send only a LF line terminator because it makes parsing easier.
client.printf("%s\n", data);
is_connected = 1;
}
else{
is_connected = -1;
}
I introduced the variable is_connected initialized as 0 for debugging. All I get is -1
.