Homebridge implementation with photon & Rasberry pi​

String readString;
TCPServer server = TCPServer(80);

String myID = System.deviceID();
int ledb = D7;
void setup()
{
pinMode(ledb, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
//digitalWrite(ledb, HIGH);
Particle.process();
Serial.begin(9600);
server.begin();

//PHOTON STATIC
//PHOTON 2 HAS 192.168.1.100
//  IPAddress myAddress(192,168,1,102);
//   IPAddress netmask(255,255,255,0);
//   IPAddress gateway(192,168,1,1);
//   IPAddress dns(192,168,1,1);
//   WiFi.setStaticIP(myAddress, netmask, gateway, dns);

//SPARK STATIC
//SPARK 1 HAS 192.168.1.102
unsigned long pucSubnetMask[1] = {0x00ffffff}; // 255.255.255.0
unsigned long pucIP_Addr[1] = {0x6601a8c0}; // 192.168.1.102
// unsigned long pucIP_DefaultGWAddr[1] = {0xfe00a8c0}; // 192.168.1.1
unsigned long pucIP_DefaultGWAddr[1] = {0x0101a8c0}; // 192.168.1.1
unsigned long pucDNS[1] = {0x0101a8c0}; // 8.8.8.8
netapp_dhcp(pucIP_Addr, pucSubnetMask, pucIP_DefaultGWAddr, pucDNS);

//WiFi.useStaticIP();
Serial.println(WiFi.localIP());
}

void loop() {
TCPClient client = server.available();

Particle.process();

if (client);
{
Particle.process();
while (client.connected())
{
Particle.process();
if (client.available())
{
char c = client.read();
if (readString.length() < 100)
{
Particle.process();
//store characters to string
readString += c;
Serial.print(c);
}

//if HTTP request has ended
if (c == ‘\n’) {
Particle.process();
///////////////
Serial.println(c); //print to serial monitor for debuging

client.println(“HTTP/1.1 200 OK”); //send new page
client.println(“Content-Type: text/html”);
client.println();

client.println(“<HTML>”);
client.println(“<HEAD>”);
client.println(“<TITLE>Arduino GET test page</TITLE>”);
client.println(“</HEAD>”);
client.println(“<BODY>”);

client.println(“<H1>Simple Arduino button</H1>”);

client.println(“<a href=\”/?on\”>ON</a>”);
client.println(“<a href=\”/?off\”>OFF</a>”);

client.println(“</BODY>”);
client.println(“</HTML>”);

delay(1);
//stopping client
client.stop();

///////////////////// control

 

Credit : jay settle

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s