Hello folks!
I am starting to toy with my imp and so far it has been a great fun. I have noticed, however, that my impee disconnects after awhile ( a variable amount of hours - say 1 to 9) and just stay offline. I was wondering if I did something in the code that might be causing that.
The code is as follows:
`// Variable to represent numbers received
tempDesejada <- 25;
tempLocal <- 25;
local out = OutputPort(“out”,“number”);
local out2 = OutputPort(“TempLocal”,“number”);
// function to measure the temperature of the surroundings
function MeasureTemp()
{
local coded = 0;
local internal_voltage= 0;
local step = 0;
local voltage_read =0;
local sampling_size = 100;
// we need to measure a lot of times for better stability
for (local i=0;i<sampling_size;i+=1)
{
imp.sleep(1/(sampling_size*2));
coded += hardware.pin2.read()/sampling_size;
}
internal_voltage = hardware.voltage();
step= internal_voltage/(math.pow(2,16)-1);
voltage_read = (coded*step);
tempLocal = voltage_read*100;
}
// input class for LED control channel
class input extends InputPort
{
name = “LED control”
type = “number”
function set(value)
{
if(value == 0)
{
// 0 = Inhibit LED operation
inhibit = 1;
hardware.pin9.write(0);
hardware.pin7.write(1);
MeasureTemp();
out.set(tempLocal);
}
else
{
// 1 = Enable LED operation
inhibit = 0;
hardware.pin9.write(1);
hardware.pin7.write(0);
}
}
}
class input2 extends InputPort
{
name = “TempDesejada”
type = “number”
function set(value)
{
local tmp = 0;
tmp = value.tofloat();
out2.set(tmp);
tempDesejada = tmp;
server.show(tempDesejada*10);
}
}
// Register with the server
imp.configure(“Blinker5i2”, [input() input2()], [out out2]);
// Configure pin 9 as an open drain output with internal pull up
hardware.pin9.configure(DIGITAL_OUT_OD_PULLUP);
hardware.pin7.configure(DIGITAL_OUT_OD_PULLUP);
hardware.pin2.configure(ANALOG_IN);
hardware.pin9.write(1);
MeasureTemp();
// End of code.`
The planner looks like the following:
So, I use an external clock to activate periodical temperature measurements, that will be sent to COSM. So far I do nothing with the HTTP input that I receive, other than displaying it.
It would be fantastic if any fo you could give me hints on why is the impee disconnecting. As a second question, is there a way to make the impee keep trying to reconnect until it suceeds?
Thanks a lot!
Best,
Pedro