I’m new to Arduino and Electric Imp and having been messing around with it for a few months now. All has been running fine for quite some time now, until the other day. All of a sudden I can’t communicate with my Imp like I use to. Was sending commands from a website to throw some switches on a device.
Now I keep getting messages about firmware update, and the device seems to keep connecting and disconnecting. Can’t get it to stay connected etc.
Keep getting this in the log:
[Agent] Alpha Imp DISCONNECTED from agent
2013-12-10 18:21:21 UTC-4: [Status] Device booting; 0.55% program storage used
2013-12-10 18:21:21 UTC-4: [Agent] Alpha Imp CONNECTED to agent.
2013-12-10 18:21:21 UTC-4: [Status] firmware update triggered
2013-12-10 18:21:28 UTC-4: [Status] Device booting; 0.55% program storage used
2013-12-10 18:21:28 UTC-4: [Agent] Alpha Imp CONNECTED to agent.
2013-12-10 18:21:28 UTC-4: [Agent] Alpha Imp DISCONNECTED from agent
2013-12-10 18:21:28 UTC-4: [Status] firmware update triggered
My code is as follows (sorry for nooby code):
Agent:
// Log the URLs we need
server.log("Turn Valve On: " + http.agenturl() + “?valve=0”);
server.log("Turn Valve Off: " + http.agenturl() + “?valve=1”);
function requestHandler(request, response) {
try {
// check if the user sent led as a query parameter
if (“valve” in request.query) {
// if they did, and valve=1… set our variable to 1
if (request.query.valve == “1” || request.query.valve == “0”) {
// convert the valve query parameter to an integer
local valveState = request.query.valve.tointeger();
// send “valve” message to device, and send valveState as the data
device.send(“valve”, valveState);
if (valveState == 1){
response.send(200, “OK, the valve is now ON”);
}else{
response.send(200, “K, the valve is now OFF”);
}
}
}
if (“lcd” in request.query) {
// if they did, and valve=1… set our variable to 1
if (request.query.lcd == “1” || request.query.lcd == “0”) {
// convert the valve query parameter to an integer
local lcdState = request.query.lcd.tointeger();
// send “valve” message to device, and send valveState as the data
device.send(“lcd”, lcdState);
if (lcdState == 1){
response.send(200, “OK, the LCD Info is now ON”);
}else{
response.send(200, “OK, the LCD Info is now OFF”);
}
}
}
if (“switch3” in request.query) {
// if they did, and valve=1… set our variable to 1
if (request.query.switch3 == “1” || request.query.switch3 == “0”) {
// convert the valve query parameter to an integer
local switchState = request.query.switch3.tointeger();
// send “valve” message to device, and send valveState as the data
device.send(“switch3”, switchState);
if (switchState == 1){
response.send(200, “OK, the ATX Power is now ON”);
}else{
response.send(200, “OK, the ATX Power is now OFF”);
}
}
}
}
catch (ex) {
response.send(500, "Internal Server Error: " + ex);
}
}
device.onconnect(function() {
server.log(“Alpha Imp CONNECTED to agent.”);
});
device.ondisconnect(function() {
server.log(“Alpha Imp DISCONNECTED from agent”);
});
// register the HTTP handler
http.onrequest(requestHandler);
Device:
// configure the imp (best practice)
imp.configure(“iGarden Api”, [], []);
hardware.pin1.configure(PWM_OUT, 0.02,0.075);
hardware.pin2.configure(PWM_OUT, 0.02,0.075);
hardware.pin9.configure(PWM_OUT, 0.02,0.075);
// create a global variabled called led,
// and assign pin9 to it
valve <- hardware.pin1;
lcd <- hardware.pin2;
atxPower <- hardware.pin9;
// configure led to be a digital output
valve.configure(DIGITAL_OUT);
lcd.configure(DIGITAL_OUT);
atxPower.configure(DIGITAL_OUT);
// function Arduino Communication
function atxPowerCall(arduinoMsg) {
server.log("ATX Power " + arduinoMsg);
atxPower.write(arduinoMsg);
}
// function Valve
function setValve(valveState) {
server.log("Set Valve: " + valveState);
valve.write(valveState);
}
// function LCD
function setLCD(lcdState) {
server.log("Set LCD: " + lcdState);
lcd.write(lcdState);
}
// register a handler for “led” messages from the agent
agent.on(“valve”, setValve);
agent.on(“lcd”,setLCD);
agent.on(“switch3”,atxPowerCall);
Any help would be appreciated.