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
ELClient Class Reference

#include <ELClient.h>

Collaboration diagram for ELClient:

Public Member Functions

 ELClient (Stream *serial, Stream *debug)
 Initialize ELClient and enable debug output.
 
 ELClient (Stream *serial)
 Initialize ELClient.
 
void Request (uint16_t cmd, uint32_t value, uint16_t argc)
 Start a request.
 
void Request (const void *data, uint16_t len)
 Append an argument to the request.
 
void Request (const __FlashStringHelper *data, uint16_t len)
 Append an argument to the request.
 
void Request (void)
 Finish the request.
 
ELClientPacketProcess (void)
 Handle serial input.
 
ELClientPacketWaitReturn (uint32_t timeout=ESP_TIMEOUT)
 Wait for a response from ESP for a given timeout.
 
boolean Sync (uint32_t timeout=ESP_TIMEOUT)
 Synchronize the communication between the MCU and the ESP.
 
void GetWifiStatus (void)
 Request WiFi status from the ESP.
 
void init ()
 Initialize ELClient protocol.
 
void DBG (const char *info)
 Send debug message over serial debug stream.
 
ELClientPacketprotoCompletedCb (void)
 Process a received SLIP message.
 
void write (uint8_t data)
 Send a byte.
 
void write (void *data, uint16_t len)
 Send several byte.
 
uint16_t crc16Add (unsigned char b, uint16_t acc)
 Create CRC for a byte add it to an existing CRC checksum and return the result.
 
uint16_t crc16Data (const unsigned char *data, uint16_t len, uint16_t acc)
 Create/add CRC for a data buffer.
 

Data Fields

Stream * _debug
 
FP< void, void * > wifiCb
 
void(* resetCb )()
 
Stream * _serial
 
boolean _debugEn
 
uint16_t crc
 
ELClientProtocol _proto
 
uint8_t _protoBuf [128]
 

Detailed Description

Definition at line 78 of file ELClient.h.

Constructor & Destructor Documentation

◆ ELClient() [1/2]

ELClient::ELClient ( Stream *  serial,
Stream *  debug 
)

Initialize ELClient and enable debug output.

ELClient(Stream* serial, Stream* debug)

Store serial streams to be used for the communication

Parameters
serialSerial stream for communication with ESP
debugSerial stream for debug output
Example for hardware serial ports
//###########################################################
// For boards using the hardware serial port!
//###########################################################
// Initialize a connection to esp-link using the normal hardware serial port both for SLIP and for debug messages.
REST rest & esp
Definition demo.ino:11
ESP esp & Serial
Definition demo.ino:9
Example for ARDUINO UNO WIFI board with I2C to serial chip connected to the ESP8266
//###########################################################
// For ARDUINO UNO WIFI board with I2C to serial chip connected to the ESP8266!
//###########################################################
// Serial port to ESP8266
#include <SC16IS750.h>
SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);
// Initialize a connection to esp-link using the I2Cuart chip of the Arduino Uno WiFi board for SLIP messages.
SC16IS750 i2cuart

Definition at line 404 of file ELClient.cpp.

Here is the call graph for this function:

◆ ELClient() [2/2]

ELClient::ELClient ( Stream *  serial)

Initialize ELClient.

ELClient(Stream* serial)

Store serial stream to be used for the communication

Parameters
serialSerial stream for communication with ESP
Example for hardware serial ports
//###########################################################
// For boards using the hardware serial port!
//###########################################################
// Initialize a connection to esp-link using the normal hardware serial port for SLIP messages.
Example for ARDUINO UNO WIFI board with I2C to serial chip connected to the ESP8266
//###########################################################
// For ARDUINO UNO WIFI board with I2C to serial chip connected to the ESP8266!
//###########################################################
// Serial port to ESP8266
#include <SC16IS750.h>
SC16IS750 i2cuart = SC16IS750(SC16IS750_PROTOCOL_I2C,SC16IS750_ADDRESS_AA);
// Initialize a connection to esp-link using the I2Cuart chip of the Arduino Uno WiFi board for SLIP messages.

Definition at line 371 of file ELClient.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ crc16Add()

uint16_t ELClient::crc16Add ( unsigned char  b,
uint16_t  acc 
)

Create CRC for a byte add it to an existing CRC checksum and return the result.

crc16Add(unsigned char b, uint16_t acc)

Parameters
bByte which CRC will be added
accExisting CRC checksum
Returns
uint16_t New CRC checksum
Example
no example code yet

Definition at line 468 of file ELClient.cpp.

Here is the caller graph for this function:

◆ crc16Data()

uint16_t ELClient::crc16Data ( const unsigned char *  data,
uint16_t  len,
uint16_t  acc 
)

Create/add CRC for a data buffer.

crc16Data(const unsigned char *data, uint16_t len, uint16_t acc)

Parameters
dataThe data buffer which will be CRCed
lenSize of the data buffer
accExisting CRC checksum
Returns
uint16_t New CRC checksum
Example
no example code yet

Definition at line 493 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DBG()

void ELClient::DBG ( const char *  info)

Send debug message over serial debug stream.

ELClient::DBG(const char* info)

Parameters
infoDebug message
Example
no example code yet

Definition at line 419 of file ELClient.cpp.

Here is the caller graph for this function:

◆ GetWifiStatus()

void ELClient::GetWifiStatus ( void  )

Request WiFi status from the ESP.

GetWifiStatus(void)

Example
// Wait for WiFi to be connected.
esp.GetWifiStatus();
Serial.print("Waiting for WiFi ");
if ((packet=esp.WaitReturn()) != NULL) {
Serial.print(".");
Serial.println(packet->value);
}
Serial.println("");
uint32_t value

Definition at line 564 of file ELClient.cpp.

Here is the call graph for this function:

◆ init()

void ELClient::init ( )

Initialize ELClient protocol.

init()

Prepare buffer for protocol

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Example
no example code yet

Definition at line 339 of file ELClient.cpp.

Here is the caller graph for this function:

◆ Process()

ELClientPacket * ELClient::Process ( void  )

Handle serial input.

Process()

Read all characters available on the serial input and process any messages that arrive, but stop if a non-callback response comes in

Returns
ELClientPacket Pointer to ELClientResponse structure with the received response
Example
void loop()
{
ELClientPacket *packet;
// process any callbacks coming from esp_link
packet = esp.Process();
if (packet != 0)
{
// process the received package //
}
}
void loop()
Definition demo.ino:73

Definition at line 115 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ protoCompletedCb()

ELClientPacket * ELClient::protoCompletedCb ( void  )

Process a received SLIP message.

protoCompletedCb(void *res)

Callback to process a SLIP message and check CRCs If a user callback function was defined in the message, ELClientResponse is called to handle the callback.

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Returns
ELClientPacket Pointer to ELClientPacket structure generated or NULL if it the message is from a callback or if an error occured
Example
no example code yet

Definition at line 31 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Request() [1/4]

void ELClient::Request ( const __FlashStringHelper *  data,
uint16_t  len 
)

Append an argument to the request.

Request(const __FlashStringHelper* data, uint16_t len)

Send additional arguments located in flash as appendment to the ESP

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Parameters
dataPointer to the buffer with the argument
lenSize of the argument buffer
Example
_elc->Request(CMD_MQTT_LWT, 0, 4);
_elc->Request(topic, strlen(topic));
_elc->Request(message, strlen(message));
_elc->Request(&qos, 1);
_elc->Request(&retain, 1);
_elc->Request();
@ CMD_MQTT_LWT
Definition ELClient.h:32

Definition at line 285 of file ELClient.cpp.

Here is the call graph for this function:

◆ Request() [2/4]

void ELClient::Request ( const void *  data,
uint16_t  len 
)

Append an argument to the request.

Request(uint16_t cmd, uint32_t value, uint16_t argc)

Send additional arguments as appendment to the ESP

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Parameters
dataPointer to the buffer with the argument
lenSize of the argument buffer
Example
_elc->Request(CMD_MQTT_LWT, 0, 4);
_elc->Request(topic, strlen(topic));
_elc->Request(message, strlen(message));
_elc->Request(&qos, 1);
_elc->Request(&retain, 1);
_elc->Request();

Definition at line 243 of file ELClient.cpp.

Here is the call graph for this function:

◆ Request() [3/4]

void ELClient::Request ( uint16_t  cmd,
uint32_t  value,
uint16_t  argc 
)

Start a request.

Request(uint16_t cmd, uint32_t value, uint16_t argc)

Start preparing a request by sending the command, number of arguments and the first argument (which can be a callback pointer)

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Parameters
cmdCommand for the ESP, see enum CmdName for available commands
valueFirst argument or pointer to a callback function
argcNumber of arguments in this request
Example
_elc->Request(CMD_MQTT_LWT, 0, 4);
_elc->Request(topic, strlen(topic));
_elc->Request(message, strlen(message));
_elc->Request(&qos, 1);
_elc->Request(&retain, 1);
_elc->Request();

Definition at line 211 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Request() [4/4]

void ELClient::Request ( void  )

Finish the request.

Request(void)

Send final CRC and SLIP_END to the ESP to finish the request

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Example
_elc->Request(CMD_MQTT_LWT, 0, 4);
_elc->Request(topic, strlen(topic));
_elc->Request(message, strlen(message));
_elc->Request(&qos, 1);
_elc->Request(&retain, 1);
_elc->Request();

Definition at line 322 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Sync()

boolean ELClient::Sync ( uint32_t  timeout = ESP_TIMEOUT)

Synchronize the communication between the MCU and the ESP.

Sync(uint32_t timeout)

Parameters
timeoutTimeout for synchronization request
Returns
boolean True if synchronization succeeds or False if it fails
Example
// Sync-up with esp-link, this is required at the start of any sketch and initializes the callbacks to the wifi status change callback. The callback gets called with the initial status right after Sync() below completes.
esp.wifiCb.attach(wifiCb); // wifi status change callback, optional (delete if not desired)
bool ok;
do
{
ok = esp.Sync(); // sync up with esp-link, blocks for up to 2 seconds
if (!ok) Serial.println("EL-Client sync failed!");
} while(!ok);
Serial.println("EL-Client synced!");
FP< void, void * > wifiCb
Definition ELClient.h:118

Definition at line 521 of file ELClient.cpp.

Here is the call graph for this function:

◆ WaitReturn()

ELClientPacket * ELClient::WaitReturn ( uint32_t  timeout = ESP_TIMEOUT)

Wait for a response from ESP for a given timeout.

WaitReturn(uint32_t timeout)

Parameters
timeoutTime in milliseconds to wait for a response, defaults to ESP_TIMEOUT
Returns
ELClientPacket Received packet or null if timeout occured
Example
// Wait for WiFi to be connected.
esp.GetWifiStatus();
Serial.print("Waiting for WiFi ");
if ((packet=esp.WaitReturn()) != NULL) {
Serial.print(".");
Serial.println(packet->value);
}
Serial.println("");

Definition at line 444 of file ELClient.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [1/2]

void ELClient::write ( uint8_t  data)

Send a byte.

write(uint8_t data)

Write a byte to the output stream and perform SLIP escaping

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Parameters
dataByte to be sent
Example
no example code yet

Definition at line 154 of file ELClient.cpp.

Here is the caller graph for this function:

◆ write() [2/2]

void ELClient::write ( void *  data,
uint16_t  len 
)

Send several byte.

write(void* data, uint16_t len)

Write some bytes to the output stream, no SLIP escaping is performed

Note
This function is usually not needed for applications. The communication to the ESP8266 is handled by the cmd, rest, mqtt, tcp and udp library parts.
Parameters
dataPointer to data buffer to be sent
lenSize of data buffer
Example
no example code yet

Definition at line 183 of file ELClient.cpp.

Here is the call graph for this function:

Field Documentation

◆ _debug

Stream* ELClient::_debug

Data stream for debug use

Definition at line 85 of file ELClient.h.

◆ _debugEn

boolean ELClient::_debugEn

Flag for debug - True = enabled, False = disabled

Definition at line 125 of file ELClient.h.

◆ _proto

ELClientProtocol ELClient::_proto

Protocol structure

Definition at line 127 of file ELClient.h.

◆ _protoBuf

uint8_t ELClient::_protoBuf[128]

Protocol buffer

Definition at line 128 of file ELClient.h.

◆ _serial

Stream* ELClient::_serial

Serial stream for communication with ESP

Definition at line 124 of file ELClient.h.

◆ crc

uint16_t ELClient::crc

CRC checksum

Definition at line 126 of file ELClient.h.

◆ resetCb

void(* ELClient::resetCb) ()

Pointer to callback function

Definition at line 121 of file ELClient.h.

◆ wifiCb

FP<void, void*> ELClient::wifiCb

Pointer to callback function

Definition at line 118 of file ELClient.h.


The documentation for this class was generated from the following files: