Problem with connector between Arduino and MS SQL Server

ieee488:
How about put your money where your mouth is and show some code?

Challenge accepted.

This is based off the ESP32 BasicHttpClient.ino example sketch. I thinned out some of it and moved the get request to its own function. That way it can be called by specialty "sensor" (anything really) functions.

You could do a similar sketch with Arduino's Ethernet WebClient example.

/**
 * BasicHTTPClient.ino
 *
 *  Created on: 24.05.2015
 *
 */

#include <Arduino.h>

#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>

#define USE_SERIAL Serial



WiFiMulti wifiMulti;
const char* ssid = "your_SSID";
const char* pass = "your_password";

char getURI[128] = "http://example.com/index.html";
//char getURI[128] = "http://example.com/flabberwab.html"; //404 Not Found - Test Response
//char getURI[128] = "http://example.com/device/5/sensor/251";


#define SENSOR_PIN 26


void setup() {
    USE_SERIAL.begin(115200);
    delay(3000);
    wifiMulti.addAP(ssid, pass);

    pinMode(SENSOR_PIN, INPUT);

    getRequest(getURI);
    delay(2000);
}

void loop() {
//  getRequest(getURI);
//  delay(5000);
  saveSensorValue();
  delay(5000);
}


void saveSensorValue(){
  char myDeviceEndPoint[128] = "http://example.com/device/5"; //your device endpoint
  int sensorVal = -1;
  char buf[12] = "";
  sensorVal = digitalRead(SENSOR_PIN);
  strcat(myDeviceEndPoint, "/sensor/"); //your sensor endpoint concatenated to your device endpoint
  strcat(myDeviceEndPoint, itoa(sensorVal, buf, 10) );
  getRequest(myDeviceEndPoint);
}



void getRequest(char* requestURI){
    // wait for WiFi connection
    if((wifiMulti.run() == WL_CONNECTED)) {
        HTTPClient http;
        USE_SERIAL.println("");
        http.begin(requestURI);

        USE_SERIAL.print("[HTTP] GET...\n");
        USE_SERIAL.println(requestURI);
        
        // start connection and send HTTP header
        int httpCode = http.GET();

        // httpCode will be negative on error
        if(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] Response code: %d\n", httpCode);

            //request made it to the server
            //and has sent back a response
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
          //Request did not reach the server
          USE_SERIAL.printf("[HTTP] Request failed, error: %s\n", http.errorToString(httpCode).c_str());
        }

        http.end();
    }
}