Connection only succeeding after code upload

Hello,

I am working on a remote start project for my car. It works very well sometimes, but I’m getting an annoying issue that I believe has to do with my setup function. I have the code written so the rgb led is lit while the board is running the setup function and then shuts off afterwards. Everything works correctly when the board boots immediately after uploading code to it, but when I unplug it and plug into a usb battery bank it only works sometimes. I can’t get it to work at all right now and I’m a bit lost. I’d appreciate some help. The led is turning on as it should, and then shuts off for a brief moment and turns right back on. It definitely shouldn’t be doing that, and doesn’t do it on successful boots. Seems like it’s rerunning the setup function or something.

Thanks,
Zain

Code:

String myPhone = “+1mynum”;
String iftttPhone = “+1iftttnum”;

bool shouldSleep = false;
const int controlPin = R03;

void lock() {
Serial.println(“Car is now locked”);

digitalWrite(controlPin, HIGH);
Dash.snooze(100);
digitalWrite(controlPin, LOW);
}

void unlock() {
Serial.println(“Car is now unlocked”);

digitalWrite(controlPin, HIGH);
Dash.snooze(120);
digitalWrite(controlPin, LOW);
Dash.snooze(120);
digitalWrite(controlPin, HIGH);
Dash.snooze(120);
digitalWrite(controlPin, LOW);
}

void start() {
Serial.println(“Car has been started”);

digitalWrite(controlPin, HIGH);
Dash.snooze(4000);
digitalWrite(controlPin, LOW);
}

void up() {
lock();
Dash.snooze(2000);
lock();
Serial.println(“Windows have been rolled up”);
}

void executeCommand(String message) {

SerialCloud.println(“r”); // means successful command sent, will be
// interpreted on Hologram’s dashboard.

if ((message == “lock”) || (message == “Lock”)) {
lock();
} else if ((message == “unlock”) || (message == “Unlock”)) {
unlock();
} else if ((message == “start”) || (message == “Start”)) {
start();
} else if ((message == “up”) || (message == “Up”)) {
up();
} else {
Serial.println(“No command parsed”);
}
}

void smsHandler(const String &sender, const rtc_datetime_t &timestamp,
const String &message) {

shouldSleep = false;

if ((sender == myPhone) || (sender == iftttPhone)) {
Serial.println("Command Recieved: ");
Serial.println(message);
executeCommand(message);
} else {
Serial.println("Command from unknown sender: ");
Serial.println(message);
}

HologramCloud.setRGB(“AQUA”);
Dash.snooze(150);
HologramCloud.offRGB();
Dash.snooze(20);
shouldSleep = true;
}

void setup() {
delay(1000);
Dash.begin();
HologramCloud.powerUp();
HologramCloud.connect();

pinMode(controlPin, OUTPUT);
digitalWrite(controlPin, LOW);
HologramCloud.setRGB(“AQUA”);

Serial.begin(9600);
SerialCloud.begin(115200);
HologramCloud.attachHandlerSMS(smsHandler);

Serial.println(“Online”);
SerialCloud.println(“Online”);
delay(1000);
HologramCloud.offRGB();
shouldSleep = true;
}

void loop() {
if ((shouldSleep) && ((HologramCloud.checkSMS()) == 0)) {
Dash.deepSleepSec(10);
shouldSleep = false;
if (!HologramCloud.isConnected()){
HologramCloud.powerUp();
HologramCloud.connect();
}
}

Dash.snooze(100);
if (HologramCloud.checkSMS() == 0) {
shouldSleep = true;
}
}

You turn the led back on in the sms handler, maybe that’s what you’re seeing?

Also, from my experimenting and reading of the Hologram source code, you probably want something like this after you wake up and power back up:

  int cnt = 0;
  // wait for modem to get good connection
  while (!HologramCloud.isConnected() && cnt++<12) {
    Dash.snooze(1000);
  }

On one of my projects I found that it takes about 6 seconds to get a good connection. I put the cnt in there just so I can bail if its not having any luck (rather than sleep()).

Also from my reading of the source the HologramCloud.powerDown() calls pollEvents() which goes through any pending SMS messages and calls the handler for each before it proceeds to shut the modem down. I haven’t completely convinced myself this is totally true yet, since something seems to lose messages sometimes. ":^)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.