Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String getRequest(String url2) {
- unsigned int wait = 1000;
- if (url2.substring(1, 7).equals("lights")) {
- wait = 100;
- } else if (url2.substring(1, 7).equals("groups")) {
- wait = 500;
- } else if (url2.substring(1, 7).equals("scenes")) {
- wait = 500;
- } else if (url2.substring(1, 8).equals("sensors")) {
- wait = 500;
- }
- while (millis() < bridgeMillis + wait) {
- }
- //bridgeMillis = millis();
- if (!clientConnect("getRequest")) {
- return "error"; //TODO!
- }
- bridgeMillis = millis();
- client.print(String("GET ") + "/api/" + hueBridgeUser + url2 + " HTTP/1.1\r\n" +
- "Host: " + hueBridgeHost + "\r\n" +
- "\r\n");
- String json;
- String line;
- int retCode = 0;
- while (client.connected()) {
- line = client.readStringUntil('\n');
- if (line.startsWith("HTTP/1.1")) {
- retCode = line.substring(9, 12).toInt(); // Get HTTP return code
- if (retCode != 200) {
- if (debug) Serial.println("http return code: " + String(retCode));
- return "error";
- }
- }
- if (line == "\r")break;
- }
- while (client.available()) {
- line = client.readStringUntil('\n');
- line = client.readStringUntil('\n');
- json = line;
- line = client.readStringUntil('\n');
- line = client.readStringUntil('\n');
- if (line == "\r")break;
- }
- return json;
- }
Advertisement
Add Comment
Please, Sign In to add comment