I’ve set up a simple web server on an Argon that will send the value of a variable as a JSON string back to the client. I can access this through cURL, but any other means (such as through a browser or python requests/pycurl libs) return an error saying the connection was closed by the peer.
Here is my Particle code:
WiFiSignal sig;
int strength;
TCPClient webClient;
TCPServer webServer = TCPServer(80);
char myIpAddress[24];
void setup() {
//IPAddress myIp = Network.localIP();
webServer.begin();
Serial.begin();
pinMode(D2, INPUT);
pinMode(D3, OUTPUT);
digitalWrite(D3, LOW);
Particle.variable("measure", &strength, INT);
}
void loop() {
strength = measureStrength();
if (webClient.connected() && webClient.available()) {
digitalWrite(D3, HIGH);
webClient.print("{\"result\": ");
webClient.print(strength);
webClient.println("}");
webClient.flush();
delay(1000);
webClient.stop();
delay(100);
}
else {
webClient = webServer.available();
}
}
int measureStrength(){
//digitalWrite(D3, HIGH);
delay(200);
sig = WiFi.RSSI();
strength = sig.getQualityValue();
delay(200);
//digitalWrite(D3, LOW);
return strength;
}
When I run curl 192.168.1.18, i get the response {“result”: n} as expected.
When I run the equivalent request in python i get the following error:
pycurl.error: (56, ‘Recv failure: Connection reset by peer’)
Any help would be much appreciated.
Thanks in advance.