Toll-Free Customer Support 24/7

/*

 *  This sketch sends data via HTTP GET requests to data.sparkfun.com service.

 *  You need to get streamId and privateKey at data.sparkfun.com and paste them

 *  below. Or just customize this script to talk to other HTTP servers.

 *

 */

#include <WiFi.h>

/* type your username */

char ssid[]     = "your ssid";

/* type your password */

char password[] = "your password";

const char* host = "iotpi.in";

const char* streamId   = "....................";

const char* privateKey = "....................";

 

WiFiClient esp32client;

void setup(void)

{

  Serial.begin(115200);

  delay(10);

  /* We start by connecting to a WiFi network */

  Serial.println();

  Serial.println();

  Serial.print("Connecting to ");

  Serial.println(ssid);

  /* Explicitly set the ESP32 to be a WiFi-client, otherwise, it by default,

     would try to act as both a client and an access-point and could cause

     network-issues with your other WiFi-devices on your WiFi-network. */

 

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)

  {

    delay(500);

    Serial.print(".");

  }

 

  Serial.println("");

  Serial.println("WiFi connected");  

  Serial.println("IP address: ");

  Serial.println(WiFi.localIP());

 }

int value = 0;

void loop(void)

{

String url="/VCET/post/postgastempinsert.php?";

String jason_string="";

char cmd=0;

while(cmd!=13)

 {

   if (Serial.available())

   {

     cmd=Serial.read();

     if(cmd!=13)

     jason_string+=cmd;

   }

 }

while(Serial.available()>0) {Serial.read();}

Serial.print("connecting to ");

Serial.println(host);

  

/* Use WiFiClient class to create TCP connections */

const int httpPort = 80;

if (!esp32client.connect(host, httpPort))

 {

   Serial.println("connection failed");

    return;

  }

/* We now create a URI for the request */

Serial.print("Requesting URL:");

Serial.println(url);

esp32client.print(String("POST ") + url + " HTTP/1.0\r\n" +

               "Host: " + host + "\r\n" +

               "Accept: *" + "/" + "*\r\n" +

               "Content-Length: " + jason_string.length() + "\r\n" +

               "Content-Type: application/json\r\n" +

               "\r\n" + jason_string

               + "\r\n");

unsigned long timeout = millis();

while (esp32client.available() == 0) {

if (millis() - timeout > 5000) {

Serial.println(">>> Client Timeout !");

esp32client.stop();

return;

}

}

  

/* Read all the lines of the reply from server and print them to Serial */

while(esp32client.available()){

String line = esp32client.readStringUntil('\r');

Serial.print(line);

}

Serial.println();

}

Back to top