POST to HTTPS from Arduino MKR1000

Hi, I’m trying to input data from a Arduino MKR1000 into a database. I have a PHP script on a server to do this which is working when I use the command from mac terminal: curl -d “depth=300”

My PHP script is:


    // Get the post data
    $reading = $_POST["depth"];
    $bottleId = 12;

    // Connect to MySQL

    // Insert into raw data table
    $sql = "INSERT INTO tbl_raw

    if ($mysqli->query($sql) === TRUE) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "
" . $mysqli->error;



I am trying to now POST to this script using Arduino IDE. For now I am not doing any sensor readings, just sending a value for “depth”. My code isn’t working and after searching online I can’t figure out why. Any help is hugely appreciated!

#include <WiFi101.h>

char ssid[] =      "XXXXX";                  // network to join
char pass[] =      "XXXXX";                  // password for wifi network

int status = WL_IDLE_STATUS;

char server[] = "";       // server URL

String postData;
String postVariable = "depth=";

WiFiClient client;

void setup() {

  // Start serial connection for feedback

  // Connect to WiFi
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to: ");
    status = WiFi.begin(ssid, pass);
    delay(10000);                         // wait 10 sec for connection

  // Log WiFi details
  Serial.print("Connected to: ");
  IPAddress ip = WiFi.localIP();
  IPAddress gateway = WiFi.gatewayIP();
  Serial.print("IP Address: ");

void loop() {

  // Readings
  int depth = 500;
  int bottleId = 11;

  postData = postVariable + depth;

  // Connect to php script at port 80
  if (client.connect(server, 80)) {
    Serial.println("Connected to server.");

    client.println("POST /XXX/XXX/test.php HTTP/1.1");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
  } else {
    Serial.println("Failed to connect to server.");

  if (client.connected()) {


I have a PHP script on a server to do this which is working when I use the command from mac terminal: curl -d "depth=300"

I doubt that. The above curl command sends a GET request to the server, the script does only work for POST requests. So you either used another curl command or a different PHP script if it worked for you.

Also here is discrepance:


  if (client.connect(server, 80)) {

HTTPS is handled on port 443 by default and the traffic is encrypted while you're connecting to port 80 (which is the default port for HTTP).

My code isn't working

Which is the worst description of a problem I can think of. No statement of what you'd expect and what you got, no serial output. The only information we get is that you were not confident with what the code did.