Card.voltage trends questions

I have a battery powered custom board with notecard WBNA (with latest LTS firmware). I’m trying to read the voltage trends using card.voltage. As you can see from this output:

14:15:09.288 -> [INFO] {"req":"card.voltage","mode":"default","hours":24,"set":true,"calibration":0,"crc":"0000:6668BE47"}

14:15:09.485 -> [INFO] {"minutes":12696,"mode":"normal","value":3.5606215888818525}

I’m not getting the voltage trend data and the notecard has been powered and running for 211.6 hours, way more than the 24 hour calculation interval specified in card.voltage.

I have some questions about card.voltage and voltage trends:

  1. Are voltage trends calculated when the hub.set mode is minimum? Does the mode have to be continuous or periodic for voltage trends to be calculated. I couldn’t find any mention in the documentation.
  2. The documentation seems to indicate that card.voltage mode=USB does not do voltage trend calculations. Is that correct? Are there other card.voltage modes that don’t do voltage trend calculations?
  3. What events reset or restart the voltage trends calculation?

Thanks,
Karl

Hi @Karl_iWell ,

Upon investigation, it appears that the on parameter, which is used to enable historic voltage trends, was not present on the card.voltage API docs. I’ve since amended the developer docs, and it will make its way onto the live website shortly. Please try the following request:

{"req":"card.voltage","mode":"default","hours":24,"set":true,"calibration":0,“on”:true}

You can see I added “on”:true to the end of your query string. If you wish to disable the historical data trend, you can use "off”:true .

To answer your questions:

  1. The voltage trends are calculated independently of the hub sync mode, so using hub.set with minimum should not affect the voltage trend.
  2. That is correct. When Notecard detects USB power, the voltage trend array is not updated, and thus no trend data is collected for this period. I believe it is only USB that behaves like this.
  3. To completely clean the voltage trend array, you’d need to perform acard.restore on your Notecard, with the delete parameter set to true. This will also completely erase all the configuration on your Notecard.

Please let me know if this resolves your issue.

Thanks,

Alex

4 Likes

Thanks Alex. That’s fixed it, I appreciate the help.

Karl

3 Likes

@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