Home Heating Automation

I made some small progress on this, but for me it was really exciting. I hosted a Apache server on my laptop and created a simple php script

<?php $fp = fsockopen("localhost", 5334, $errno, $errstr, 30); if(!$fp){ echo "$errstr ($errno)"; } else{ fwrite($fp,$_POST["angle"]); fclose($fp); } ?>

This sends data to the arduino running this sketch.

#include <Servo.h>

Servo myServo;

int incomingByte = 0;

int nPulseWidth = 1500 ; // 1500, defined in servo.h

String readString;


void setup()
{

  myServo.attach(2);
  
  // the library sets all servos to 1500 ms pulse width by default, this is center for a steering servo
  Serial.begin(9600);
  Serial.println("Completed setup");  
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }
  
  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    incomingByte = readString.toInt();  //convert readString into a number
    nPulseWidth = (int) (incomingByte/90.0*1000 + 500);
    myServo.writeMicroseconds(nPulseWidth);
    Serial.print("Sending Servo: ");
    Serial.println(nPulseWidth,DEC);
    readString="";    
  }  
}

It was just exciting being able to control the servo from my tablet over our intranet.