//#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include #include Adafruit_INA219 ina219; float shuntvoltage = 0; float busvoltage = 0; float current_mA = 0; float current_A = 0; float loadvoltage = 0; float power_W = 0; // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = "token"; void setup() { Serial.begin(9600); Cayenne.begin(token); uint32_t currentFrequency; ina219.begin(); } void loop() { Cayenne.run(); shuntvoltage = ina219.getShuntVoltage_mV(); busvoltage = ina219.getBusVoltage_V(); current_mA = ina219.getCurrent_mA(); loadvoltage = busvoltage + (shuntvoltage / 1000); current_A = current_mA / 1000; power_W = current_A * loadvoltage; } CAYENNE_OUT(V0) { Cayenne.virtualWrite(V0, loadvoltage); } CAYENNE_OUT(V1) { Cayenne.virtualWrite(V1, current_A); } CAYENNE_OUT(V2) { Cayenne.virtualWrite(V2, power_W); }