Hi,
I have electron device, i wrote a sample code for testing. i try to put the device sleep mode every after 30 sec for 5 sec. Initially it was working but after doing multiple time OTA, it doesn’t work.
Device kind of get struck i wont able to see any output. and red led glows some time then whole led turn OFF. compiling and flashing is success full
my code snippet:
uint16_t WAIT_INTERVAL = 30000;
int ledb = D7;
int ledc = D6;
//String Input;
uint32_t Start_time;
uint32_t end_time;
double value;
int command(String );
void measure_cell(void);
void radio_down(void);
Timer timer(WAIT_INTERVAL, radio_down, false);
void sleep_mode(){
}
SYSTEM_MODE(AUTOMATIC);
void setup(){
Particle.variable("cell", &value, DOUBLE);
Particle.function("cmd", command);
pinMode(ledb, OUTPUT);
digitalWrite(ledb, LOW);
if(Particle.connected()){
Particle.publish("radio_on", "0", PUBLIC);
}
Serial.begin(9600);
timer.start();
Start_time = System.ticks();
}
void loop(){
if(Particle.connected()){
digitalWrite(ledb, HIGH);
}
}
int command (String cmd){
if(cmd == "reset"){
if(Particle.connected()){
Particle.publish("Restting", "1",PUBLIC);
}
delay(1000);
System.reset();
return 1;
} else if(cmd == "cell"){
measure_cell();
return -1;
} else{
if(Particle.connected()){
Particle.publish("call function", "0", PUBLIC);
}
return 0;
}
}
void radio_down(void){
end_time = System.ticks();
uint32_t duration = (((end_time - Start_time) / System.ticksPerMicrosecond()) / 1000000);
Serial.println(duration);
delay(1000);
System.sleep( SLEEP_MODE_DEEP, 5); //THIS CAUSE DEVICE TO STRUCK.
}
void measure_cell(void){
FuelGauge fuel;
value = fuel.getVCell();
if(Particle.connected()){
Particle.publish("fuel-level", String(value));
}
}
please help me with it, as i am new to electron