1st Project - Electricimp, 2 servos & iPhone to control central heating

https://vimeo.com/53318486

Dude share. share code.

In the planner there are 3 Nodes:

Node1: ‘HTTP In’ >
Node2: ‘HeatingController’ (custom code) >
Node3: ‘Cosm’

Node1 ‘HTTP in’ allows values to be passed into Node2 ‘HeatingController’. Node2 also polls a temperature sensor that passes the value to Node 3. This updates a Cosm feed (https://cosm.com/feeds/85039). The docs should help explain this. I also found a very good article here: http://www.instructables.com/id/impBot-a-Pan-Tilt-Electric-Imp-Robot/. Here’s the code for the HeatingController. it’s work in progress:

[code]

// Control central heating
// iPhone app sends temperature value between 5-24 degree celeius to service
// Service sends value to imp
// imp controls 2 servos that can press buttons on central heating control panel to ajust heating

// Configure pin as an open drain output with internal pull up
hardware.pin7.configure(PWM_OUT_STEPS, 0.020, 0.5, 1000);
hardware.pin8.configure(PWM_OUT_STEPS, 0.020, 0.5, 1000);
hardware.pin2.configure(ANALOG_IN);

// Input port to accept color values
class TempInput extends InputPort
{
function set(val)
{
server.show(val);
if (val > 0) {
for(local i=0;i<val;i+=1){
hardware.pin7.write(0.071);
imp.sleep(0.8);
hardware.pin7.write(0.05);
imp.sleep(2);
}
} else {
for(local i=0;i>val;i-=1){
hardware.pin8.write(0.06);
imp.sleep(0.8);
hardware.pin8.write(0.076);
imp.sleep(2);
}
}
//server.sleepfor(50000.0);
}
}

// Temperature Sensor Class for SA56004X
class TemperatureSensor
{
// Retrieve temperature (from local sensor) in deg C
function getTemperature()
{
local v = 0;
local cV = 0;
v = hardware.pin2.read();
//cV = hardware.voltage() * v / 65535;
cV = (5.0 * v) / 65535;
return cV * 100;
}
}

// Instantiate the sensor
local sensor = TemperatureSensor();

// Output port to send temperature readings
local output = OutputPort(“Temperature”, “number”);

imp.configure(“HeatingController”, [TempInput()], [output]);
//imp.setpowersave(true);

// set servo to intial state
hardware.pin8.write(0.076);

// Capture and log a temperature reading every 5s
function capture()
{
// Set timer for the next capture
imp.wakeup(30.0, capture);

// Output the temperature
local temp = sensor.getTemperature();
output.set(temp);
server.show(format("voltage: %f", hardware.voltage()));
server.show(format("%3.1fC", temp));

}
// Start capturing temperature
capture();

//local v = 0;
//local cV = 0;
//v = hardware.pin2.read();
//cV = hardware.voltage() * v / 65535;
//server.show(format(“temp: %d”, cV * 100));

// End of code.

[code]

awesome

How do you use your Iphone to send commands?