Skip to content

Commit

Permalink
scanmytesla fastmode
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmaster187 committed Oct 11, 2019
1 parent a181393 commit 3a6f9ec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ TeslaLogger/bin/nohup.out
TeslaLogger/GrafanaDashboards/*
TeslaLogger/bin/VERSION
TeslaLogger/bin/geofence-private.csv
TeslaLogger/bin/nohup.out
TeslaLogger/bin/SRTM-Data/*
9 changes: 9 additions & 0 deletions TeslaLogger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ static void Main(string[] args)
{
RefreshToken(wh);

if (wh.scanMyTesla != null)
wh.scanMyTesla.FastMode(false);

// Alle States werden geschlossen
DBHelper.CloseChargingState();
DBHelper.CloseDriveState(wh.lastIsDriveTimestamp);
Expand Down Expand Up @@ -234,6 +237,9 @@ static void Main(string[] args)
lastOdometerChanged = DateTime.Now;

Logfile.Log("Driving");
if (wh.scanMyTesla != null)
wh.scanMyTesla.FastMode(true);

double missingOdometer = DBHelper.currentJSON.current_odometer - odometerLastTrip;

if (odometerLastTrip != 0)
Expand All @@ -256,6 +262,9 @@ static void Main(string[] args)
{
lastCarUsed = DateTime.Now;
Logfile.Log("Charging");
if (wh.scanMyTesla != null)
wh.scanMyTesla.FastMode(true);

wh.IsDriving(true);
DBHelper.StartChargingState();
currentState = TeslaState.Charge;
Expand Down
26 changes: 24 additions & 2 deletions TeslaLogger/ScanMyTesla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ScanMyTesla
{
string token;
System.Threading.Thread thread;
bool fastmode = false;
bool run = true;

public ScanMyTesla(string token)
Expand All @@ -23,15 +24,36 @@ public ScanMyTesla(string token)
thread.Start();
}

public void FastMode(bool fast)
{
Logfile.Log("ScanMyTesla FastMode: " + fast.ToString());
fastmode = fast;
}

private void Start()
{
string response = "";

while (run)
{
try
{
string response = GetDataFromWebservice().Result;
System.Threading.Thread.Sleep(5000);

if (!fastmode && response == "not found")
{
for (int s = 0; s < 300; s++)
{
if (fastmode)
break;

System.Threading.Thread.Sleep(1000);
}
}

response = GetDataFromWebservice().Result;
if (response.StartsWith("not found") || response.StartsWith("ERROR:"))
System.Threading.Thread.Sleep(5000);
System.Threading.Thread.Sleep(1000);
else
{
InsertData(response);
Expand Down
2 changes: 1 addition & 1 deletion TeslaLogger/WebHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class WebHelper
static int MapQuestCount = 0;
static int NominatimCount = 0;

ScanMyTesla scanMyTesla;
public ScanMyTesla scanMyTesla;

static WebHelper()
{
Expand Down

0 comments on commit 3a6f9ec

Please sign in to comment.