Gbox 4.20
Grow box automation and monitoring - <a href='https://sites.google.com/site/growboxguy/'>https://sites.google.com/site/growboxguy/</a>
 
Loading...
Searching...
No Matches
test.ino
Go to the documentation of this file.
1
5#include <ELClient.h>
6#include <ELClientCmd.h>
7
8// Initialize a connection to esp-link using the normal hardware serial port both for
9// SLIP and for debug messages. Esp-link will show the debug messages in the uC console
10// because they are not SLIP framed.
12
13// Initialize CMD client (for GetTime)
15
16// Callback made from esp-link to notify of wifi status changes
17// Here we just print something out for grins
18void wifiCb(void* response) {
19 ELClientResponse *res = (ELClientResponse*)response;
20 if (res->argc() == 1) {
21 uint8_t status;
22 res->popArg(&status, 1);
23
24 if(status == STATION_GOT_IP) {
25 Serial.println("WIFI CONNECTED");
26 } else {
27 Serial.print("WIFI NOT READY: ");
28 Serial.println(status);
29 }
30 }
31}
32
33// Callback made form esp-link to notify that it has just come out of a reset. This means we
34// need to initialize it!
35void resetCb(void) {
36 Serial.println("EL-Client (re-)starting!");
37 bool ok = false;
38 do {
39 ok = esp.Sync(); // sync up with esp-link, blocks for up to 2 seconds
40 if (!ok) Serial.println("EL-Client sync failed!");
41 } while(!ok);
42 Serial.println("EL-Client synced!");
43}
44
45void setup() {
46 Serial.begin(115200);
47
48 // Sync-up with esp-link, this is required at the start of any sketch and initializes the
49 // callbacks to the wifi status change callback. The callback gets called with the initial
50 // status right after Sync() below completes.
51 esp.wifiCb.attach(wifiCb); // wifi status change callback, optional (delete if not desired)
52 esp.resetCb = resetCb;
53 resetCb();
54}
55
56static uint32_t last;
57
58void loop() {
59 esp.Process();
60
61 if ((millis()-last) > 4000) {
62 Serial.println("requesting time");
63 uint32_t t = cmd.GetTime();
64 Serial.print("Time: "); Serial.println(t);
65
66 last = millis();
67 }
68}
Definitions for ELClientCmd.
Definitions for ELClient.
@ STATION_GOT_IP
Definition ELClient.h:51
int16_t popArg(void *data, uint16_t maxLen)
Extract an argument from the response packet.
void wifiCb(void *response)
Definition test.ino:18
void setup()
Definition test.ino:45
ELClientCmd cmd & esp
Definition test.ino:14
ELClient esp & Serial
Definition test.ino:11
void resetCb(void)
Definition test.ino:35
void loop()
Definition test.ino:58