I have been running some test code on a Boron 2G/3G running OS:2.0.1 where I control shutting down and running the modem. I have attached the test code below.
The problem is, when running this code, and I hit flash device on the workbench, the device doesn’t automatically go into DFU mode. I have to press the Mode and settings buttons manually. I can’t find anything that would lock the serial port to cause the following error. Please help
ERROR
:::: PUTTING DEVICE INTO DFU MODE
Device not found: chocolate_chipotle
CODE
#include "Particle.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
#define MODEM_POWER_ON_INTERVAL 1200000 // 20 mins
#define MIN_MODEM_ON_TIME 120000 // 2 mins
enum modem_states
{
MODEM_OFF,
MODEM_CONNECTING,
MODEM_CONNECTED
};
uint32_t current_modem_state = MODEM_OFF;
uint32_t previous_modem_state = MODEM_OFF;
bool modem_on_period_expired;
bool modem_status;
bool led_state;
FuelGauge igh_power;
void set_modem_on_period_expired( void );
void igh_power_mgt_turn_on_modem( void );
void print_system_data( void );
void pulse_led( uint32_t modem_state );
void led_control_counter( void );
Timer modem_power_on_timer( MODEM_POWER_ON_INTERVAL, igh_power_mgt_turn_on_modem, true );
Timer min_modem_on_period( MIN_MODEM_ON_TIME, set_modem_on_period_expired, true );
Timer print_system_data_timer( 5000, print_system_data );
LEDStatus modem_off(RGB_COLOR_GREEN, LED_PATTERN_BLINK, LED_SPEED_SLOW);
LEDStatus modem_connecting(RGB_COLOR_GREEN, LED_PATTERN_BLINK, LED_SPEED_FAST);
LEDStatus modem_connected(RGB_COLOR_CYAN, LED_PATTERN_FADE, LED_SPEED_SLOW);
void print_system_data( void )
{
if( false == modem_status )
{
current_modem_state = MODEM_OFF;
}
else
{
if( Cellular.ready() &&
Particle.connected() )
{
current_modem_state = MODEM_CONNECTED;
}
else
{
current_modem_state = MODEM_CONNECTING;
}
}
// Serial.print("modem: "); Serial.print( Cellular.ready() );
// Serial.print(", cloud: "); Serial.println( Particle.connected() );
}
void igh_power_mgt_init( void )
{
Cellular.on();
Cellular.connect();
Particle.connect();
modem_status = true;
modem_on_period_expired = false;
if( false == min_modem_on_period.isActive() )
{
min_modem_on_period.start();
}
Serial.println("System init ---------------------->1");
}
void set_modem_on_period_expired( void )
{
modem_on_period_expired = true;
Serial.println("been on for too long --------------->2");
}
void igh_power_mgt_turn_on_modem( void )
{
if( true == modem_power_on_timer.isActive() )
{
// this means the modem is off
modem_power_on_timer.stop();
// stop this time is it is running
}
if( false == modem_status )
{
Cellular.on();
Cellular.connect();
Particle.connect();
modem_status = true;
modem_on_period_expired = false;
if( false == min_modem_on_period.isActive() )
{
min_modem_on_period.start();
}
Serial.println("modem turned on ------------------>3");
}
}
void igh_power_mgt_modem_comms_manager( void )
{
if( (true == modem_on_period_expired) &&
(true == Time.isValid()) &&
(true == modem_status) )
{
Cellular.disconnect();
Cellular.off();
modem_status = false;
if( false == modem_power_on_timer.isActive() )
{
modem_power_on_timer.start();
}
Serial.println("modem turned off ----------------->4");
}
if( current_modem_state != previous_modem_state )
{
// update led state
pulse_led( current_modem_state );
previous_modem_state = current_modem_state;
}
}
void pulse_led( uint32_t modem_state )
{
switch( modem_state)
{
case MODEM_OFF:
modem_off.setActive(true);
modem_connecting.setActive(false);
modem_connected.setActive(false);
break;
case MODEM_CONNECTING:
modem_off.setActive(false);
modem_connecting.setActive(true);
modem_connected.setActive(false);
break;
case MODEM_CONNECTED:
modem_off.setActive(false);
modem_connecting.setActive(false);
modem_connected.setActive(true);
break;
default:
modem_off.setActive(false);
modem_connecting.setActive(false);
modem_connected.setActive(false);
break;
}
}
void setup()
{
Serial.begin(19200);
print_system_data_timer.start();
igh_power_mgt_init();
}
void loop()
{
igh_power_mgt_modem_comms_manager();
}