Hello everyone!
I am having some problems, wondering if anyone here could help.
I spent the last 5 days (around 30 hours) to set up Homebridge on Linux and get my Arduino to properly work with it.
I've got as far as having 2 LEDs connected. I can turn them on with Siri or the Home app in IOS10 and even get the status updated. So good so far.
BUT, my problem is if I turn or lets say the RED LED, it turns on (status updates OK), then I go to turn on my GREEN LED then it turns on, but the RED LED turns off as well.
My coding is not the nicest, and I am still just just learning Arduino,
but if enyone could help I'd really appreciate it!
My code is below:
/* Arduino UNO based homebridge accessories
It is very basic coding
Has 2 leds connected one to PIN 9 and one to PIN 10
ESP8266 -05 modul is communicating on HW serial port
Was having some problems with homebridge so some unnecesary delays might be in place
*/
#include "WiFiEsp.h" //I found this library to be working with my module
#include <ESP8266_TCP.h>
// ESP8266 Class
ESP8266_TCP wifi;
// Target Access Point
const char* ssid = "XXX XXX"; //Input your Wifi's SSID here
const char* pass = "XXX XXX"; // Input your Wifi's password here
const int redPin = 9; // RED LED connected to PIN 9
const int greenPin = 10; // GREEN LED connected to PIN 10
String readString;
WiFiEspServer server(80); // Start server on port 80
void setup(){
Serial.begin(9600); // my ESP8266 is now running this speed
pinMode(redPin, OUTPUT); // Set this pin to output
pinMode(greenPin, OUTPUT); // Set this pin to output
WiFi.init(&Serial); // initialize ESP module
delay(1000);
WiFi.begin(ssid, pass); // Start ESP8266-05 module and log on to network
delay(1000);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Start the server
server.begin();
delay(1000);
}
void loop(){
// Create a client connection
WiFiEspClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
delay(100);
//control Arduino pins
int val;
if (req.indexOf("redon") != -1)
val = 1; // if "redon" command is received change "val" to "1"
else if (req.indexOf("redoff") != 1)
val = 0; // if "redoff" command is received change "val" to "0"
int val1;
if (req.indexOf("greennon") != -1)
val1 = 1; // if "greennon" command is received change "val1" to "1"
else if (req.indexOf("greenoff") != 1)
val1 = 0; // if "greenoff" command is received change "val1" to "0"
else {
client.stop();
return;
}
{ //update the PINS
digitalWrite(redPin, val);
digitalWrite(greenPin, val1);
//Respond to homebrdige server
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
delay(1);
//stopping client
client.stop();
//clearing string for next read
// readString="";
}
}
}
}
}
Since there don't seem to be good instructible, I will probably make a good one with all the codes once I get it working so others will benefit of all of this
Anyways thanks for all the help in advance!