Skip to content

Instantly share code, notes, and snippets.

@dhavalsavalia
Created February 15, 2019 03:09
Show Gist options
  • Save dhavalsavalia/b36c68a2a02e1e885f757b222168e542 to your computer and use it in GitHub Desktop.
Save dhavalsavalia/b36c68a2a02e1e885f757b222168e542 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "<WIFI SSID>";
const char* password = "<WIFI PASSWORD>";
const char* host = "<HOST IP>";
int wifiStatus;
void setup() {
delay(1000);
Serial.begin(115200);
WiFi.mode(WIFI_OFF);
delay(1000);
WiFi.mode(WIFI_STA);
pinMode(2, OUTPUT);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Your are connecting to;");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
}
void loop() {
HTTPClient http; //Declare object of class HTTPClient
//Post Data
String postData = "lat0=10.100&lon0=20.200&lat1=30.300&lon1=40.400";
http.begin("http://192.168.43.178:8000/ambulance/api/v1/ambulance/1/"); //Specify request destination
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
http.addHeader("Authorization", "JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VybmFtZSI6InJvb3QiLCJleHAiOjIxNTIxOTM3MjQsImVtYWlsIjoiIn0.V2kHNpR_7PFYOOsijJaJ3XjfFXddQA9JqhfGcVfQVCw");
int httpCode = http.POST(postData); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
digitalWrite(2, HIGH);
http.end(); //Close connection
delay(5000); //Post Data at every 5 seconds
digitalWrite(2, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment