@abucknall
As I’ve used card.voltage trends, I noticed that readings at the top of the hour are all zero for daily, weekly and monthly trends. Our application has the Notecard in minimum mode. I wrote the following Arduino code to test this (setup and loop shown):
> void setup() {
>
> // Initialize Debug Output
> Serial.begin(DEBUG_BAUD_RATE);
> delay(4000);
> Serial.println("serial is ready");
> notecard.setDebugOutputStream(serialDebug);
>
> notecard.begin();
> // KWN need to add battery voltage check, use card.voltage
> //float batteryLevel = network::readVoltageTrends();
>
> float voltage;
> float calibration; //KWN read calibration value
> int trend_Hours; //KWN voltage trend hours
> float trend_Vmin, trend_Vmax, trend_Vave; //KWN voltage trend values
> float trend_Daily, trend_Weekly, trend_Monthly; //KWN voltage trend
>
> // Configure Notecard to synchronize with Notehub periodically, as well as
> // adjust the frequency based on the battery level, allow DFU download
> J * req = notecard.newRequest("hub.set");
> JAddStringToObject(req, "product", productUID);
> JAddStringToObject(req, "mode","minimum"); //changed by KWN - removed auxgpio
> //JAddNumberToObject(req, "outbound",15); //KWN
> //JAddNumberToObject(req,"inbound",60); //KWN
> // JAddStringToObject(req, "mode", "minimum,auxgpio");
> J * resp = notecard.requestAndResponse(req);
> bool success = !notecard.responseError(resp);
> JDelete(resp);
>
> req = notecard.newRequest("card.voltage");
> JAddStringToObject(req, "mode", "default");
> JAddNumberToObject(req,"hours",720);
> JAddBoolToObject(req,"set",true);
> JAddNumberToObject(req,"calibration",0.0);
> JAddBoolToObject(req,"on",true);
>
>
> J *rsp = notecard.requestAndResponse(req);
> if (rsp != NULL) {
> voltage = JGetNumber(rsp, "value");
> serialDebug.printf("Voltage: %f\n", voltage);
> calibration = JGetNumber(rsp, "calibration"); //KWN - read calibration value
> serialDebug.printf("Calibration: %f\n", calibration);
> notecard.deleteResponse(rsp);
> trend_Hours = JGetNumber(rsp,"hours");
> trend_Vmin = JGetNumber(rsp,"vmin");
> trend_Vmax = JGetNumber(rsp,"vmax");
> trend_Vave = JGetNumber(rsp, "vavg");
> trend_Daily = JGetNumber(rsp,"daily");
> trend_Weekly = JGetNumber(rsp,"weekly");
> trend_Monthly = JGetNumber(rsp,"monthly");
>
> Serial.println("[setupTemplate] begin");
> }
>
> req = notecard.newRequest("note.template");
> JAddStringToObject(req, "file", "voltage.qos");
> J * body = JAddObjectToObject(req, "body");
> JAddNumberToObject(body, "hours", 12);
> JAddNumberToObject(body, "vmin", 14.1);
> JAddNumberToObject(body, "vmax",14.1);
> JAddNumberToObject(body,"vave",14.1);
> JAddNumberToObject(body,"daily",14.1);
> JAddNumberToObject(body,"weekly",14.1);
> JAddNumberToObject(body,"monthly",14.1);
> notecard.sendRequest(req);
>
> req = notecard.newRequest("note.add");
> JAddStringToObject(req, "file", "voltage.qos");
> J * body1 = JAddObjectToObject(req, "body");
> JAddNumberToObject(body1, "hours", trend_Hours);
> JAddNumberToObject(body1, "vmin", trend_Vmin);
> JAddNumberToObject(body1, "vmax", trend_Vmax);
> JAddNumberToObject(body1, "vave", trend_Vave);
> JAddNumberToObject(body1,"daily",trend_Daily);
> JAddNumberToObject(body1,"weekly",trend_Weekly);
> JAddNumberToObject(body1,"monthly",trend_Monthly);
> JAddBoolToObject(req, "sync", false);
> JAddBoolToObject(req,"full",true); //KWN makes sure zero values are added
> notecard.sendRequest(req);
>
>
> // Optimize voltage variable behaviors for LiPo battery2
> /* Removed call to Optimize voltage since we are in default mode and we are handling battery management in firmware
> Serial.println("[setup/network::optimizeVoltage] start");
> network::optimizeVoltage();
> */
> // Initialize Notecard Aux pins for GPIO
> // network::enableGPIO();
> }
>
>
> void goToSleep() {
> // For Cats boards version 1.4 and lower
> int pin10val = 0;
> int cntr = 0;
> //timestamp_t ts;
> //uint64_t capture_offset;
> //result_status_t conn_status;
> int time_left;
>
> time_left = 900;
> Serial.printf("wake up in %d seconds\n", time_left);
> delay(time_left * 1000);
> }
>
> void loop() {
>
> uint64_t capture_offset;
> //result_status_t conn_status;
> int time_left;
> bool updated;
>
> //checkAPGConfig();
> //readSensorsAndUpload();
> //network::testVoltageTrends();
> float voltage;
> float calibration; //KWN read calibration value
> int trend_Hours; //KWN voltage trend hours
> float trend_Vmin, trend_Vmax, trend_Vave; //KWN voltage trend values
> float trend_Daily, trend_Weekly, trend_Monthly; //KWN voltage trend
>
> J * req = notecard.newRequest("card.voltage");
> JAddNumberToObject(req,"hours",720);\
>
> J *rsp = notecard.requestAndResponse(req);
> if (rsp != NULL) {
> voltage = JGetNumber(rsp, "value");
> serialDebug.printf("Voltage: %f\n", voltage);
> calibration = JGetNumber(rsp, "calibration"); //KWN - read calibration value
> serialDebug.printf("Calibration: %f\n", calibration);
> notecard.deleteResponse(rsp);
> trend_Hours = JGetNumber(rsp,"hours");
> trend_Vmin = JGetNumber(rsp,"vmin");
> trend_Vmax = JGetNumber(rsp,"vmax");
> trend_Vave = JGetNumber(rsp, "vavg");
> trend_Daily = JGetNumber(rsp,"daily");
> trend_Weekly = JGetNumber(rsp,"weekly");
> trend_Monthly = JGetNumber(rsp,"monthly");
> }
>
> Serial.println("[setupTemplate] begin");
> req = notecard.newRequest("note.template");
> JAddStringToObject(req, "file", "voltage.qos");
> J * body = JAddObjectToObject(req, "body");
> JAddNumberToObject(body, "hours", 12);
> JAddNumberToObject(body, "vmin", 14.1);
> JAddNumberToObject(body, "vmax",14.1);
> JAddNumberToObject(body,"vave",14.1);
> JAddNumberToObject(body,"daily",14.1);
> JAddNumberToObject(body,"weekly",14.1);
> JAddNumberToObject(body,"monthly",14.1);
> notecard.sendRequest(req);
>
> req = notecard.newRequest("note.add");
> JAddStringToObject(req, "file", "voltage.qos");
> J * body1 = JAddObjectToObject(req, "body");
> JAddNumberToObject(body1, "hours", trend_Hours);
> JAddNumberToObject(body1, "vmin", trend_Vmin);
> JAddNumberToObject(body1, "vmax", trend_Vmax);
> JAddNumberToObject(body1, "vave", trend_Vave);
> JAddNumberToObject(body1,"daily",trend_Daily);
> JAddNumberToObject(body1,"weekly",trend_Weekly);
> JAddNumberToObject(body1,"monthly",trend_Monthly);
> JAddBoolToObject(req, "sync", false);
> JAddBoolToObject(req,"full",true); //KWN makes sure zero values are added
> notecard.sendRequest(req);
>
> //network::startSync();
> req = notecard.newRequest("hub.sync");
> JAddBoolToObject(req, "allow", true);
> notecard.sendRequest(req);
>
> goToSleep();
> }
Here are the results of card.voltage trend readings taken every 15 minutes:
3:32:38 PM - {"daily":0.04,"hours":313,"monthly":0,"vave":4.230735,"vmax":4.68,"vmin":3.48,"weekly":-0.45}
3:17:37 PM - {"daily":0,"hours":312,"monthly":0,"vave":4.2329807,"vmax":4.68,"vmin":3.48,"weekly":0}
3:02:53 PM - {"daily":0,"hours":312,"monthly":0,"vave":4.2329807,"vmax":4.68,"vmin":3.48,"weekly":0}
2:47:35PM - {"daily":0,"hours":312,"monthly":0,"vave":4.2329807,"vmax":4.68,"vmin":3.48,"weekly":-0.45}
2:32:35 PM - {"daily":0,"hours":312,"monthly":0,"vave":4.2329807,"vmax":4.68,"vmin":3.48,"weekly":-0.45}
2:17:34 PM - {"daily":0,"hours":311,"monthly":0,"vave":4.2350483,"vmax":4.68,"vmin":3.48,"weekly":0}
2:02:33 PM - {"daily":0,"hours":311,"monthly":0,"vave":4.2350483,"vmax":4.68,"vmin":3.48,"weekly":0}
The weekly trend should never to 0. When I've run this test for longer periods of time, the monthly number also goes to 0.
Any idea if this is a bug or am I doing something wrong? In our application I would like to monitor these trends values to determine if the battery is not being charged by the solar panel.
Thanks,
Karl