I am trying to use a SIM card from Telkomsel (Indonesia) with a 2G Electron. I flashed the electron the firmware from when I was claiming the device, and I am manually setting the network credentials in the code. I am also changing the keepAlive time (I have tried different lengths of time for the KeepAlive but it continues to lose connectivity). However, the Electron is still unable to maintain cloud connection. It maintains connection for 6 hours maximum (often for less time) and is then unable to reconnect to the cloud and goes into listening mode.
Is there anything else I need to do to adapt to the third party SIM card? Any suggestions for improving cloud connectivity or explanations for the inability to maintain cloud connection? Below is the code I am trying to use.
#include "cellular_hal.h"
STARTUP(cellular_credentials_set("telkomsel", "wap", "wap123", NULL)); //configures cellular network
int voltage = A0;
int cur1 = A1;
int cur2 = A2;
int cur3 = A3;
double i1;
double i2;
double i3;
double v;
bool publish;
String locationCode = "CMK";
double csdf = 4000; //current sensor downgrading factor
Timer timer(3600000, measure); // after certain amount of time calls measure function
void setup() {
Particle.keepAlive(30);
pinMode(voltage, INPUT);
pinMode(cur1, INPUT);
pinMode(cur2, INPUT);
pinMode(cur3, INPUT);
timer.start();
publish = false;
}
void loop(){
if (publish){
Particle.publish(locationCode+"_C1",String::format("%f", i1), 60);
Particle.publish(locationCode+"_C2",String::format("%f", i2), 60);
Particle.publish(locationCode+"_C3",String::format("%f", i3), 60);
Particle.publish(locationCode+"_V",String::format("%f", v), 60);
publish = false;
}
}
// makes measurements and stores in i1, i2, i3, and v, sets publish to true
void measure() {
v = maxVoltage(voltage);
i1 = findCurrent(cur1);
i2 = findCurrent(cur2);
i3 = findCurrent(cur3);
publish = true;
//String data = String::format("%f,%f,%f,%f", voltageReading, cur1Reading,cur2Reading,cur3Reading);
}
double maxVoltage(int pin){
int max = -1;
int i=0;
int data =-1;
while(i<1000){
data = analogRead(pin);
if (data>max){
max = data;
}
delay(1);
i++;
}
return max*0.0698344;
}
double findCurrent(int pin){
int max = -1;
int min = 4096;
int data = -1;
int i=0;
while(i<1000){
data = analogRead(pin);
if (data>max){
max = data ;
}
if (data<min){
min = data;
}
i++;
delay(1);
}
return (max-min)*csdf*0.000056983;
}