Hi,
My photon loses it’s connection to the could every minute or so, and then immediately comes back online. This only started occurring when I added an I2C current sensor and new code, so it shouldn’t be the wifi signal or hardware. The RSSI is -65.
My main loop doesn’t do much but just sit there waiting for the device time to hit a multiple of 5 min, and then upload a reading from the sensor. Maybe this is the issue? I added in a 5sec delay, but it hasn’t solved the problem. Here’s a pic of the disconnects, and my code.
Any help would be greatly appreciated!
Thanks Particle Community.
#include "Adafruit_INA219.h"
#include <application.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
//Name pins, name functions, create variables////////////////////////////////////////////
int load = A0;
bool state = 0;
double w_inst = 0; // current power, in W per m^2
double wh_cum = 12; // cumulative energy collected today, in Wh / m^2
double burn = 0; //amount of time to run the light for, in milliseconds
int i=0;
double shuntvoltage = 0;
double busvoltage = 0;
double current_mA = 0;
double loadvoltage = 0;
char publishData[40] = ""; //empty variable 40 units long which will hold data being sent to cloud
char publishBurn[45] = ""; //empty variable 45 units long which will hold data being sent to cloud
void setup(void)
{
uint32_t currentFrequency;
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();
Time.zone(-7); //set time zone to PT
pinMode(load, OUTPUT); // sets pin as output
digitalWrite(load,LOW); // sets it Low
Particle.variable("Current",current_mA);
Particle.variable("Voltage",loadvoltage);
Particle.variable("Power",w_inst);
Particle.variable("Energy",wh_cum);
}
void loop(void)
{
// delay to fix connectivity issues?
delay(5000);
i++;
//calculate power, energy, and publish every 5 min
if ( 8 <= Time.hour() && Time.hour() <= 19){
//if ( Time.minute() <= 15){
if (Time.minute() % 5 == 0){
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
w_inst = (current_mA / 1000) * loadvoltage ;
wh_cum += w_inst / 12;
sprintf(publishData,"%.2f ||| %.2f ||| %.2f",current_mA,w_inst,wh_cum); //URL Example https://community.particle.io/t/example-using-ifttt-google-drive/8908
Particle.publish("datawrite",publishData,30); //ttl number must be less than writeinterval
//calculate burn time
burn = ( wh_cum / (1.15 * 12.6) ) * 60 * 60 * 1000; // calculates the burn, in mseconds, based on lightbulb current and voltage
// reset counters
state = 1;
delay(60000); //wait for the minute to no longer be a multiple of 5
}
}
//burn off stored energy
if ( Time.hour() < 8 && state == 1){
//if ( Time.minute() > 15 && state == 1){
sprintf(publishBurn,"Begin %.2f Wh burn lasting %.2f minutes",wh_cum,burn / 1000 / 60);
Particle.publish("burnnotice",publishBurn,30); //ttl number must be less than writeinterval
while (burn > 0 ){
digitalWrite(load,HIGH); // turn on light
delay(10000);
burn -= 10000; //decrement burn by 10s
}
state = 0; //reset state
wh_cum = 0; // reset cumulative energy
digitalWrite(load,LOW); // turn off light
Particle.publish("burnnotice","Burn Completed!",30); //ttl number must be less than writeinterval
}
//end program
}