Hello,
I have a wifi 1010, therm shield and an ENV shield stacked.
I have the following code attached. I am able to upload the code and it will run 2-4 loops before it stalls out.
As a php programmer, I feel like maybe I am running out of memory? I am concerned that I am opening too many connections and I need to close them but am not sure how to do that.
I would love any help,
Matt
#include "thingProperties.h"
#include <Arduino_MKRENV.h>
#include <Arduino_MKRTHERM.h>
#include <ArduinoHttpClient.h>
String apiKeyValue = "key";
void setup() {
Serial.begin(9600);
delay(1500);
if (!ENV.begin()) {
Serial.println("Failed to initialize MKR ENV shield!");
while(1);
}
if (!THERM.begin()) {
Serial.println("Failed to initialize MKR THERM shield!");
while (1);
}
}
void loop() {
temp = ENV.readTemperature(FAHRENHEIT);
ktype = THERM.readTemperature();
ktype = (ktype * 1.8) + 32;
char serverAddress[] = "site.com"; // server address
int port = 80;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
Serial.println("making POST request");
String contentType = "application/x-www-form-urlencoded";
String postData = "api_key=" + apiKeyValue + "&ambient_temp=" + temp + "&ktemp=" + ktype;
client.post("/data_post.php", contentType, postData);
// read the status code and body of the response
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait five seconds");
Serial.flush();
delay(5000);
}