Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>
extern "C"{
#include "user_interface.h"
}
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
IPAddress staticIP(192, 168, 1, 22); //ESP static ip
IPAddress gateway(192, 168, 1, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
IPAddress dns(192, 168, 1, 1); //DNS
HTTPClient http;
void signalDone()
{
digitalWrite(2, HIGH);
delay(10);
digitalWrite(2, LOW);
}
void setup()
{
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
Serial.begin(9600);
WiFi.config(staticIP, subnet, gateway,dns);
WiFi.mode(WIFI_STA);
WiFi.begin("ACCESS_POINT_NAME", "PASSWORD");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
delay(500);
// Signal the Attiny we're done
signalDone();
}
void loop() {
char c;
while (Serial.available())
{
c = Serial.read();
if ( c == '1')
http.begin("http://192.168.1.9:5005/Room/playpause"); //HTTP
if ( c == '2')
http.begin("http://192.168.1.9:5005/Room/next"); //HTTP
if ( c == '3')
http.begin("http://192.168.1.9:5005/Room/volume/+5"); //HTTP
if ( c == '4')
http.begin("http://192.168.1.9:5005/Room/volume/-5"); //HTTP
http.GET();
String payload = http.getString();
if (payload!="{\"status\":\"success\"}")
{
http.GET();
}
http.end();
signalDone();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.