Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to do any RAPI operations until OpenEVSE has started up. #216

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 43 additions & 30 deletions src/src.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "wifi.h"
#include "web_server.h"
#include "ohm.h"
#include "openevse.h"
#include "input.h"
#include "emoncms.h"
#include "mqtt.h"
Expand Down Expand Up @@ -65,10 +66,6 @@ void setup() {

DEBUG.printf("Free: %d\n", ESP.getFreeHeap());

lcd_display(F("OpenEVSE WiFI"), 0, 0, 0, LCD_CLEAR_LINE);
lcd_display(currentfirmware, 0, 1, 5 * 1000, LCD_CLEAR_LINE);
lcd_loop();

// Read saved settings from the config
config_load_settings();
DBUGF("After config_load_settings: %d", ESP.getFreeHeap());
Expand All @@ -88,20 +85,6 @@ void setup() {

rapiSender.setOnEvent(on_rapi_event);
rapiSender.enableSequenceId(0);

// Check state the OpenEVSE is in.
if (0 == rapiSender.sendCmd("$GS"))
{
if(rapiSender.getTokenCnt() >= 3)
{
const char *val = rapiSender.getToken(1);
DBUGVAR(val);
state = strtol(val, NULL, 10);
DBUGVAR(state);
}
} else {
DBUGLN("OpenEVSE not responding or not connected");
}
} // end setup

// -------------------------------------------------------------------
Expand All @@ -120,19 +103,49 @@ loop() {
rapiSender.loop();
divert_current_loop();

// Gives OpenEVSE time to finish self test on cold start
if ( (millis() > 5000) && (rapi_read==0) ) {
DBUGLN("first read RAPI values");
handleRapiRead(); //Read all RAPI values
rapi_read=1;
if(OPENEVSE_STATE_STARTING != state &&
OPENEVSE_STATE_INVALID != state)
{
// Read initial state from OpenEVSE
if (rapi_read == 0)
{
lcd_display(F("OpenEVSE WiFI"), 0, 0, 0, LCD_CLEAR_LINE);
lcd_display(currentfirmware, 0, 1, 5 * 1000, LCD_CLEAR_LINE);
lcd_loop();

DBUGLN("first read RAPI values");
handleRapiRead(); //Read all RAPI values
rapi_read=1;
}

// -------------------------------------------------------------------
// Do these things once every 2s
// -------------------------------------------------------------------
if ((millis() - Timer3) >= 2000) {
DEBUG.printf("Free: %d\n", ESP.getFreeHeap());
update_rapi_values();
Timer3 = millis();
}
}
// -------------------------------------------------------------------
// Do these things once every 2s
// -------------------------------------------------------------------
if ((millis() - Timer3) >= 2000) {
DEBUG.printf("Free: %d\n", ESP.getFreeHeap());
update_rapi_values();
Timer3 = millis();
else
{
// Check if we can talk to OpenEVSE
if ((millis() - Timer3) >= 1000)
{
// Check state the OpenEVSE is in.
if (0 == rapiSender.sendCmd("$GS"))
{
if(rapiSender.getTokenCnt() >= 3)
{
const char *val = rapiSender.getToken(1);
DBUGVAR(val);
state = strtol(val, NULL, 10);
DBUGVAR(state);
}
} else {
DBUGLN("OpenEVSE not responding or not connected");
}
}
}

if(wifi_client_connected())
Expand Down