hello all,
we have a board with a p1 which we program via usb in the factory. we flash device os 2.0.1 (2 parts) and our application. then we power cycle and test if the device operates correctly
the application starts by logging some stuff, does a modbus request and, if no credentials are set, does Wifi.listen() where it will wait for the user to enter credentials etc. see code below.
now what we see is that after factory programming the device will not log anything, it does not do the modbus request but does go to listen mode. restart the device and same thing
i can add/join/claim the device and the application starts logging and works fine
a function is added to clear the credentials. it will do:
WiFi.clearCredentials();
EEPROM.clear();
System.reset();
after this is done, when i restart the device, it does log and it does do the modbus request
anyone any idea why it does not log after the first time programming?
thanks so much
frank
#include "Particle.h"
#include "MeasureModule.h"
#include "MMFirmware.h"
#include "ModBusClient.h"
#include "Site.h"
#include "Socket.h"
#include "SocketFirmware.h"
#include "Version.h"
#include "ParticleAPI.h"
#include "AVRProgrammer.h"
#include "ChargingAlgorithm.h"
#include "edge-site.h"
PRODUCT_ID(12543);
PRODUCT_VERSION(1);
// does not startup connectivity only after Particle.connect() is called
SYSTEM_MODE(SEMI_AUTOMATIC);
// allow loop to continue without wifi
SYSTEM_THREAD(ENABLED);
// WiFi Antenne
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL)); // selects the u.FL antenna
SerialLogHandler logHandler(LOG_LEVEL_ALL);
LEDStatus blinkOrange(RGB_COLOR_ORANGE, LED_PATTERN_BLINK, LED_SPEED_NORMAL, LED_PRIORITY_IMPORTANT);
// blinkOrange.setActive(true);
unsigned char debug_out = 0;
#define LOOP_CYCLE_PERIOD 1000
#define LOOP_ID_PERIOD 100
#define DEBUG_COUNTER 10
unsigned long next_id_nr_time;
unsigned long next_cycle_time;
unsigned char debug_counter;
unsigned int current_id_nr;
unsigned int read_or_write;
unsigned int interrupt_loop;
unsigned long pwh_last_publish = 0;
void setup() {
// just so i can hit 'connect' in time to capture serial logging
delay(2000);
WiFi.setHostname("edge-ev-hub");
Log.info("System version: %s", System.version().c_str());
Log.info("DeviceID: %s",System.deviceID().c_str());
Log.info("Hostname: %s",WiFi.hostname().c_str());
int errorCode = ERROR_OKAY;
// do not do this in the factory
if(WiFi.hasCredentials()) {
Log.info("got credentials");
// tell the server/particle cloud how we are doing, every 5 minutes
Particle.publishVitals(300);
}
// test
// fuse default: 0b.0110.0010 --> internal rc 8 mhz / 8
// fuse programmed: 0b.1xxx.1111 --> external crystal 16 mhz / 1
// mm_set_fuses used bit-bang mode to read and possible set the fuses
// after this the spi mode van be used (e.g. to program the atmega)
mmf_set_fuses();
// initialize measure module (spi)
mm_init();
// initialize modbus client (serial)
mb_init();
// checking mm version and upgrade if needed
unsigned short version = mm_version();
Log.info("mm version: v%d.%d.%d",(int) (version>>12),(int) (version>>8&0xf),(int) (version&0xff));
int need_upgrade = mmf_needs_upgrade(version);
if(need_upgrade) {
Log.info("upgrading mm");
errorCode = mmf_firmware_update();
Log.info("upgrading finished with %d", errorCode);
}
// internal boot test
if(!WiFi.hasCredentials()) {
if(errorCode == ERROR_OKAY) {
int mm_read_status;
int tries = 3;
do {
mm_read_status = mm_read();
Log.info("got return code %d", mm_read_status);
} while( (mm_read_status == MM_READ_CRC_ERROR) && ((tries--)>0));
if(mm_read_status != MM_READ_OK) {
errorCode = ERROR_SPI;
} else {
Log.info("got values %f, %f, %f",site_current.current_current[0],site_current.current_current[1],site_current.current_current[2]);
if((site_current.current_current[0] > 1.0) ||
(site_current.current_current[1] > 1.0) ||
(site_current.current_current[2] > 1.0)) {
errorCode = ERROR_MEASURE;
}
}
}
Log.info("sending error code %d", errorCode);
mb_send_id_and_error_factory(errorCode);
Log.info("entering listen mode");
WiFi.listen();
Log.info("done with listen mode");
// delay(2000);
}
--- end so on ---