I’m putting together Twilio > imp application to take SMS directed at my Twilio # and turn it into a controller for my imp. I have three LEDs (red, yellow, green) and wrote a simple blink() program to toggle them on and off, so I know the hardware’s okay.
I configured my Messaging Request URL to point to my agent URL, and have the following code as my agent to forward along the message body to the imp:
function mywebserver(request,res) { t<-http.urldecode(request.body); if(t.From=="+1<myNumber>") { device.send("sendbody",t.Body); res.send(200,"okay"); } }
On the device, I have the following code to toggle the LEDs individually, or just set them to blink:
`imp.configure(“GetSMS”, [], []);
agent.on(“sendbody”,function(value){ // value = the body of the SMS message
if(value==“Red”){
toggleRed();
}
if(value=="Green"){
toggleGreen();
}
if(value=="Yellow"){
toggleYellow();
}
if(value=="Blink"){
blinkAll();
}
});
// Define the LED vars
rLED <- hardware.pin1;
yLED <- hardware.pin2;
gLED <- hardware.pin5;
// Configure as Digital Outputs
rLED.configure(DIGITAL_OUT);
yLED.configure(DIGITAL_OUT);
gLED.configure(DIGITAL_OUT);
rState <- 0;
yState <- 0;
gState <- 0;
// Set the state (0 = off)
rLED.write(rState);
yLED.write(yState);
gLED.write(gState);
// Blink them in unison
function blinkAll() {
// flip the current LED States
if(rState == 0) {
rState = 1;
} else {
rState = 0;
}
if(yState == 0) {
yState = 1;
} else {
yState = 0;
}
if(gState == 0) {
gState = 1;
} else {
gState = 0;
}
// Apply them
rLED.write(rState);
yLED.write(yState);
gLED.write(gState);
//imp.wakeup(3.0, blinkAll);
}
function toggleRed() {
if(rState == 0) {
rState = 1;
} else {
rState = 0;
}
rLED.write(rState);
}
function toggleYellow() {
if(yState == 0) {
yState = 1;
} else {
yState = 0;
}
yLED.write(yState);
}
function toggleGreen() {
if(gState == 0) {
gState = 1;
} else {
gState = 0;
}
gLED.write(gState);
}
`
From the IDE and can see the device online / engine running indicators are green.
The device log is not responsive, though, beyond
2014-02-17 13:33:38 UTC-5: [Status] Device booting; 4.2% program storage used
2014-02-17 13:33:38 UTC-5: [Device] imp.configure command is deprecated
Thoughts?