Skip to content

Commit

Permalink
Don't send data if RTC hasn't been updated since boot
Browse files Browse the repository at this point in the history
-If RTC is not working don't capture and don't send data, make error visible to user (blue leds keep blinking permanently).
-Added function RTCupdate() grouping commands.
-version change to 0.9.3-A
-Minor changes
  • Loading branch information
vicobarberan committed Apr 14, 2016
1 parent 7df0bba commit 4a62730
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
12 changes: 6 additions & 6 deletions sck_beta_v0_9/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#define decouplerComp true //Only for version Goteo 1.0

#if F_CPU == 8000000
#define FirmWare "1.1-0.9.0-B"
#define FirmWare "1.1-0.9.3-A"
#else
#define FirmWare "1.0-0.9.0-B"
#define FirmWare "1.0-0.9.3-A"
#endif

/*
Expand Down Expand Up @@ -39,13 +39,13 @@ WIFLY Firmware Setting
#define networks 0
#if (networks > 0)
static char* mySSID[networks] = {
"SSID1" , "SSID2" , "SSID3" };
"SSID1" , "SSID2" };
static char* myPassword[networks] = {
"PASS1" , "PASS2" , "PASS3" };
"PASS1" , "PASS2" };
static char* wifiEncript[networks] = {
WPA2 , WPA2 , WPA2 };
WPA2 , WPA2 };
static char* antennaExt[networks] = {
INT_ANT , INT_ANT , INT_ANT };
INT_ANT , INT_ANT };
#endif

#define TWI_FREQ 400000L //Frecuencia bus I2C
Expand Down
51 changes: 31 additions & 20 deletions sck_beta_v0_9/SCKAmbient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ uint32_t NumUpdates = 0; // Min. number of sensor readings before publishing
uint32_t nets = 0;
boolean sleep = true;
uint32_t timetransmit = 0;
uint32_t timeMICS = 0;
uint32_t timeMICS = 0;
boolean RTCupdatedSinceBoot = false;

void SCKAmbient::ini()
{
Expand Down Expand Up @@ -168,18 +169,15 @@ void SCKAmbient::ini()
}
#endif
#endif
byte retry = 0;
if (base_.checkRTC())
{
if (server_.time(time))
{
while (!base_.RTCadjust(time)&&(retry<5)) retry++;
#if debugEnabled
if (!debugON) Serial.println(F("Updating RTC..."));
#endif
}
if (server_.RTCupdate(time)) {
RTCupdatedSinceBoot = true;
#if debugEnabled
if (!debugON) Serial.println(F("RTC Updated!!"));
#endif
} else {
#if debugEnabled
else if (!debugON) Serial.println(F("Fail updating RTC!!"));
if (!debugON) Serial.println(F("RTC Update Failed!!"));
sleep = false;
#endif
}
}
Expand Down Expand Up @@ -783,7 +781,7 @@ boolean SCKAmbient::debug_state()

void SCKAmbient::execute()
{
if (terminal_mode) // Telnet (#data + *OPEN* detectado )
if (terminal_mode) // Telnet (#data + *OPEN* detectado )
{
sleep = false;
digitalWrite(AWAKE, HIGH);
Expand All @@ -796,13 +794,26 @@ void SCKAmbient::execute()
timetransmit = millis();
TimeUpdate = base_.readData(EE_ADDR_TIME_UPDATE, INTERNAL); // Time between transmissions in sec.
NumUpdates = base_.readData(EE_ADDR_NUMBER_UPDATES, INTERNAL); // Number of readings before batch update
updateSensors(sensor_mode);
if (!debugON) // CMD Mode False
{
if ((sensor_mode)>NOWIFI) server_.send(sleep, &wait_moment, value, time);
#if USBEnabled
txDebug();
#endif
if (!debugON) { // CMD Mode False
if (RTCupdatedSinceBoot) {
updateSensors(sensor_mode);
if ((sensor_mode)>NOWIFI) server_.send(sleep, &wait_moment, value, time);
#if USBEnabled
txDebug();
#endif
} else {
if (server_.RTCupdate(time)) {
RTCupdatedSinceBoot = true;
#if debugEnabled
if (!debugON) Serial.println(F("RTC Updated!!"));
#endif
} else {
#if debugEnabled
if (!debugON) Serial.println(F("RTC Update Failed!!"));
if (!debugON) Serial.println(F("With no valid time it's useless to take readings!!"));
#endif
}
}
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions sck_beta_v0_9/SCKServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ boolean SCKServer::time(char *time_) {
return ok;
}

boolean SCKServer::RTCupdate(char *time_){
byte retry = 0;
if (base__.checkRTC()){
if (time(time_)) {
while (retry<5) {
retry++;
if(base__.RTCadjust(time_)) {
return true;
}
}
}
}
return false;
}

void SCKServer::json_update(uint16_t updates, long *value, char *time, boolean isMultipart)
{
#if debugServer
Expand Down
1 change: 1 addition & 0 deletions sck_beta_v0_9/SCKServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SCKServer {
boolean connect();
void addFIFO(long *value, char *time);
void readFIFO();
boolean RTCupdate(char *time);
private:

};
Expand Down

0 comments on commit 4a62730

Please sign in to comment.