SPEEEduino_LowLevel_Library.cpp

Includes:
"SPEEEduino_LowLevel_Library.h"
<avr/pgmspace.h>

Introduction

Use the links in the table of contents to the left to access the documentation.



Functions

beginDeepSleep

Initiates the deep sleep feature for the ESP8266 module

beginSingleConnection

Initiates a connection when the module is set to single connection mode, in other words, AT+CIPMUX? returns 0

beginTCPServer

Starts a TCP server with a certain port

disconnectAP

Disconnect from an access point.

endConnection

Closes the current connection

getLocalIP

Get the IP address of the module. If the module is in station mode, it retrieves the assigned IP address of the module. If the module is in SoftAP mode, it will retrieve the IP address of the access point created by the module.

joinAP

Joins an access point with the SSID and password specified. Only works for PSK-based networks (password only)

listAP

Lists the access points around the device

listVersion

Lists the firmware version of the firmware on board. This information contains the AT version, SDK version and compile time

openLink

Opens the serial link from the SPEEEduino to the ESP-01 module

rawInput

Inputs raw text into the ESP-01 module. This command INCLUDES the carriage return and newline characters

WARNING:

Make sure that you manually check for the response with the wait() function

receiveData

Waits for data with a timeout.

reset
sendDataMultipleConnection

Sends data on multiple connection mode, this must be run directly after `startSingleConnection()`. Once this completes successfully, you MUST start reading the input

sendDataSingleConnection

Sends data on single connection mode, this must be run directly after `startSingleConnection()`. Once this completes successfully, you MUST start reading the input

setConnectionAmount

Sets the mode for the number of simultaneous connections allowed

setDHCPEnabled

Sets the DHCP to be enabled or disabled for both station and softAP modes. This

setIP

Sets parameters for static IP allocation without DHCP.

setSoftAPSettings

Sets the SoftAP's settings, such as the name of the hotspot, password and so on

setSSLBufferSize

Sets the SSL buffer size.

setStationName

Sets name of the ESP8266 client (in other words, when it's connected to a Wi-Fi hotspot)

setWiFiMode

Sets the Wi-Fi mode of the device to operate as a Wi-Fi station (client), access point, or both. This setting will be saved in non-volatile memory

slowOpenLink

Opens the serial link from the SPEEEduino to the ESP-01 module, and imposes an artificial delay

smokeTest

A simple smoke test to see if the module responds

wait

Waits for a certain serial input. This also prints out the serial data before hitting the correct case if debug mode is enabled.

writeCommandFromPROGMEM

Writes a command from PROGMEM to the ESP8266's serial ports


beginDeepSleep


Initiates the deep sleep feature for the ESP8266 module

int16_t SPEEEduino_LowLevel::beginDeepSleep(
    uint16_t sleepTime,
    bool blocking) 
Parameters
sleepTime

Time to sleep, in milliseconds. This must not exceed the length of an unsigned 16-bit integer

blocking

Whether or not to block the SPEEEduino's MCU using the wait() function

Return Value

0, if it successfully sleeps and recovers and -1 if it times out (when blocking=true), and always 0 if blocking = false

Discussion

WARNING:

This is a blocking function with potentially long delays if the blocking flag is set to true


beginSingleConnection


Initiates a connection when the module is set to single connection mode, in other words, AT+CIPMUX? returns 0

int16_t SPEEEduino_LowLevel::beginSingleConnection(
    ConnectionType type,
    String remoteIP,
    String remotePort) 
Parameters
type

The type of connection, such as TCP, UDP or SSL (actually TLSv1.1)

remoteIP

The IP address or domain of the server it's connecting to

remotePort

The port of the server it's connecting to

Return Value

0 if successfully established connection, 1 if there's an error with the connection, 2 if the connection socket is in use, and -1 if the command timed out


beginTCPServer


Starts a TCP server with a certain port

int16_t SPEEEduino_LowLevel::beginTCPServer(
    TCPServer createServer,
    uint16_t port) 
Parameters
createServer

Whether to create or delete the server on the port.

port

The port to create the TCP server on

Return Value

0 if the TCP server is initialised, 1 if the TCP server did not initialise, -1 if the command timed out


disconnectAP


Disconnect from an access point.

int16_t SPEEEduino_LowLevel::disconnectAP() 
Return Value

0 if successfully disconnected access point, 1 if it failed, and -1 if it timed out


endConnection


Closes the current connection

int16_t SPEEEduino_LowLevel::endConnection(
    int8_t linkID = -1) 
Parameters
linkID

Optional, link ID, ranging from 0 to 4 if you're using multiple connections, and 5 if you want to close all connections. Do not input this parameter if you're using a single connection.

Return Value

0 if the connection is closed, 1 if the command failed, -1 if the command timed out


getLocalIP


Get the IP address of the module. If the module is in station mode, it retrieves the assigned IP address of the module. If the module is in SoftAP mode, it will retrieve the IP address of the access point created by the module.

int16_t SPEEEduino_LowLevel::getLocalIP() 
Return Value

0, if it successfully returns the IP address and -1 if it times out


joinAP


Joins an access point with the SSID and password specified. Only works for PSK-based networks (password only)

int16_t SPEEEduino_LowLevel::joinAP(
    String ssid,
    String password) 
Parameters
ssid

The SSID of the access point

password

The password of the access point

Return Value

0 if successfully joined access point, 1 if it failed, and -1 if it timed out


listAP


Lists the access points around the device

int16_t SPEEEduino_LowLevel::listAP() 
Return Value

0 if successfully listed all the access points, -1 if the request timed out


listVersion


Lists the firmware version of the firmware on board. This information contains the AT version, SDK version and compile time

int16_t SPEEEduino_LowLevel::listVersion() 
Return Value

0, if it responds and -1 if it times out


openLink


Opens the serial link from the SPEEEduino to the ESP-01 module

void SPEEEduino_LowLevel::openLink() 

rawInput


Inputs raw text into the ESP-01 module. This command INCLUDES the carriage return and newline characters

WARNING:

Make sure that you manually check for the response with the wait() function

void SPEEEduino_LowLevel::rawInput(
    String input) 
Parameters
input

Your input into the ESP8266 module


receiveData


Waits for data with a timeout.

ReturnedData SPEEEduino_LowLevel::receiveData(
    ConnectionAmount connectionAmount,
    uint32_t timeOut=20000) 
Parameters
connectionAmount

SINGLE or MULTIPLE, depending on what did you start your ESP8266 module with

timeOut

Maximum time to wait for the response before the connection is considered to be timed out

Return Value

A ReturnedData struct containing the link ID (-1 if you're using single connection) and the returned data in the form of a String

Discussion

WARNING:

This function is a BLOCKING function, meaning that it will pause your program execution


reset


int16_t SPEEEduino_LowLevel::reset() 
Return Value

0, if it successfully resets and -1 if it times out

Discussion

Software resets the module


sendDataMultipleConnection


Sends data on multiple connection mode, this must be run directly after `startSingleConnection()`. Once this completes successfully, you MUST start reading the input

int16_t SPEEEduino_LowLevel::sendDataMultipleConnection(
    String& data,
    uint8_t linkID) 
Parameters
data

The data to send into the connection socket

linkID

The ID of the link assigned to you

Return Value

0 if the data is successfully sent, 1 if the socket failed to initialise, 2 if the connection failed after sending, -1 if the process timed out


sendDataSingleConnection


Sends data on single connection mode, this must be run directly after `startSingleConnection()`. Once this completes successfully, you MUST start reading the input

int16_t SPEEEduino_LowLevel::sendDataSingleConnection(
    String& data) 
Parameters
data

The data to send into the connection socket

Return Value

0 if the data is successfully sent, 1 if the socket failed to initialise, 2 if the connection failed after sending, -1 if the process timed out


setConnectionAmount


Sets the mode for the number of simultaneous connections allowed

int16_t SPEEEduino_LowLevel::setConnectionAmount(
    ConnectionAmount amount) 
Parameters
name

The host name of the ESP8266 station that you want to set it to

Return Value

0 if successfully set the name of the station, 1 if the command failed, and -1 if the command timed out


setDHCPEnabled


Sets the DHCP to be enabled or disabled for both station and softAP modes. This

int16_t SPEEEduino_LowLevel::setDHCPEnabled(
    bool enabled) 
Parameters
enabled

Whether or not to enable the DHCP server/client

Return Value

0 if successfully set DHCP mode, -1 if it timed out

Discussion

WARNING:

This function is only for station mode only!


setIP


Sets parameters for static IP allocation without DHCP.

int16_t SPEEEduino_LowLevel::setIP(
    bool permanent,
    String ip,
    String gateway="",
    String netmask="") 
Parameters
permanent

Boolean to specify if the setting should be permanent or temporary

ip

The IP address to set

gateway

The address of the default gateway. Optional.

netmask

The subnet mask of the network. Optional.

Return Value

0 if successfully set static IP, 1 if there's an issue, and -1 if it times out

Discussion

WARNING:

You must turn DHCP off with setDHCPEnabled() first before setting the IP! This function has NOT been tested on a real device before!


setSoftAPSettings


Sets the SoftAP's settings, such as the name of the hotspot, password and so on

int16_t SPEEEduino_LowLevel::setSoftAPSettings(
    String& ssid,
    String& password,
    uint8_t channel,
    EncryptionMethod encryptionMethod) 
Parameters
ssid

The SSID or name of the hotspot being broadcasted

password

The password of the hotspot

channel

The Wi-Fi channel to broadcast on. Typically 1 to 14, prefer 1, 5, 9, 13 as they do not overlap

Return Value

0 if successfully set the name of the station, 1 if the command failed, and -1 if the command timed out


setSSLBufferSize


Sets the SSL buffer size.

int16_t SPEEEduino_LowLevel::setSSLBufferSize(
    uint16_t bufferSize) 
Parameters
bufferSize

The desired size of the SSL buffer. Must be within 2048 to 4096

Return Value

0 if successfully set the buffer size, 1 if there's an error, 2 if the buffer size is not within range of [2048,4096] and -1 if the command timed out


setStationName


Sets name of the ESP8266 client (in other words, when it's connected to a Wi-Fi hotspot)

int16_t SPEEEduino_LowLevel::setStationName(
    String& name) 
Parameters
name

The host name of the ESP8266 station that you want to set it to

Return Value

0 if successfully set the name of the station, 1 if the command failed, and -1 if the command timed out


setWiFiMode


Sets the Wi-Fi mode of the device to operate as a Wi-Fi station (client), access point, or both. This setting will be saved in non-volatile memory

int16_t SPEEEduino_LowLevel::setWiFiMode(
    WiFiMode mode) 
Parameters
mode

The mode of the device to set. Accepts STATION, AP and BOTH

Return Value

0 if successfully set Wi-Fi mode, -1 if it timed out


slowOpenLink


Opens the serial link from the SPEEEduino to the ESP-01 module, and imposes an artificial delay

void SPEEEduino_LowLevel::slowOpenLink(
    int delayTime=5000) 
Parameters
delayTime

The time to wait before opening the serial port. Defaults to 5 seconds.


smokeTest


A simple smoke test to see if the module responds

int16_t SPEEEduino_LowLevel::smokeTest() 
Return Value

0, if the test is successful and -1 if the test times out


wait


Waits for a certain serial input. This also prints out the serial data before hitting the correct case if debug mode is enabled.

int16_t SPEEEduino_LowLevel::wait(
    char *values,
    uint16_t timeOut) 
Parameters
values

Semicolon delimited expected C-style string

timeOut

Timeout in milliseconds

Return Value

-1 if timed out, 0, 1, 2, ... if the data matches one of the values in the values string


writeCommandFromPROGMEM


Writes a command from PROGMEM to the ESP8266's serial ports

void SPEEEduino_LowLevel::writeCommandFromPROGMEM(
    const char *text) 
Parameters
text

The constant from PROGMEM to write to the ESP8266 module