-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbasestation.h
More file actions
88 lines (66 loc) · 2.41 KB
/
cbasestation.h
File metadata and controls
88 lines (66 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <WiFiMulti.h>
#include <ArduinoJson.h>
#include "encode.h"
#include "gwradio.h"
// This code
// 1. Connects to a WiFi network
// 2. Loops:
// a. Makes an http request to a URL
// b. Parses the response, expecting an integer between 0 and 1000
// c. Outputs that on PIN D0 as a voltage between 0 and 3.6V
// d. Waits for 60 seconds
// Wifi settings are wifiMulti.addAP(ssid, password) below
#define CMD_INTERVAL 20
class CBaseStation{
private:
class ConsoleEcho{
private:
std::string str;
std::string strtolog;
CBaseStation *pBS;
public:
void setBS( CBaseStation *ptmp){pBS=ptmp;}
void echo(){Serial.println(str.c_str()); strtolog+=str; str="";}
void logstr(const char *pstr){pBS->getEchoData(pstr);}
void log(){pBS->getEchoData(strtolog.c_str()); strtolog="";}
void begin(long tmp){Serial.begin(tmp);}
void print(const char *tmp){str=str+tmp;}
// void print(long tmp){str=str+tmp;}
void print(std::string tmp){str=str+tmp;}
void print(String tmp){str=str+tmp.c_str();}
void println(const char *tmp=""){print(tmp);echo();}
void println(std::string tmp){print(tmp);echo();}
void println(String tmp){print(tmp);echo();}
} SerialB;
WiFiClientSecure client;
WiFiMulti wifiMulti;
//ConsoleEcho SerialB;
// The code calls the path on the host below and
// expects a response with one line containing an integer
// between 0 and maxMetric.
const char* host = "9nxvzfnhrd.execute-api.us-east-1.amazonaws.com";
const char* cmdpath = "/v1/commands?latest=sent&value=false";
const char* updatecmdpath = "/v1/commands?sent=true&cid=";
const char* updateackpath = "/v1/commands?ack=true&cid=";
const char* logpath = "/v1/satlog?bid=1&rssi=0&data=";
const char* consolelogpath = "/v1/errorlog?bid=1&data=";
const int httpsPort = 443;
const int serialBaudRate = 115200;
const int delayWaitingForWifiConnection = 500;
unsigned long lastCmd = 0;
public:
gwradio radio;
CBaseStation(){SerialB.setBS(this);}
bool isCmdTime();
void connectWifi();
void updateTransmittedCmd(const char * strdata);
void updateAckCmd(CBufferObj &bufobj);
void updateAllTransmittedCommands();
void updateAllReceivedCommands();
void insertSatData(CBufferObj &bufobj);
void getEchoData(const char * strdata);
void getLastCommand();
};