Created
December 6, 2018 02:45
-
-
Save longprep/d4621f03bb4c6f3aa9d338e6a05640fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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