Firmware for an ad-hoc mesh network of Internet-of-Things devices based on LoRa (Long Range radio) that can be deployed quickly and cheaply.
Duck Class Referenceabstract

#include <Duck.h>

Public Member Functions

 Duck ()
 Construct a new Duck object. More...
 
 Duck (String id)
 Construct a new Duck object. More...
 
 ~Duck ()
 
void setupSerial (int baudRate=115200)
 Setup serial connection. More...
 
void setupRadio (float band=CDPCFG_RF_LORA_FREQ, int ss=CDPCFG_PIN_LORA_CS, int rst=CDPCFG_PIN_LORA_RST, int di0=CDPCFG_PIN_LORA_DIO0, int di1=CDPCFG_PIN_LORA_DIO1, int txPower=CDPCFG_RF_LORA_TXPOW)
 Setup the radio component. More...
 
void setupWifi (const char *ap="🆘 DUCK EMERGENCY PORTAL")
 Setup WiFi access point. More...
 
int setupDns ()
 Setup DNS. More...
 
void setupWebServer (bool createCaptivePortal=false, String html="")
 Setup web server. More...
 
void setupInternet (String ssid, String password)
 Setup internet access. More...
 
void setupOTA ()
 
int sendPayloadStandard (String msg="", String topic="", String senderId="", String messageId="", String path="")
 Send a duck LoRa message. More...
 
bool isWifiConnected ()
 Check wifi connection status. More...
 
bool ssidAvailable (String ssid)
 Check if the give access point is available. More...
 
String getSsid ()
 Get the access point ssid. More...
 
String getPassword ()
 Get the wifi access point password. More...
 

Protected Member Functions

int startReceive ()
 Tell the duck radio to start receiving packets from the mesh network. More...
 
int startTransmit ()
 Tell the duck radio to start receiving packets from the mesh network. More...
 
virtual void run ()=0
 Implement the duck's specific behavior. More...
 
virtual void setupWithDefaults (String ssid, String password)
 Setup a duck with default settings. More...
 
virtual int getType ()=0
 
virtual int reconnectWifi (String ssid, String password)
 
void processPortalRequest ()
 Handle request from emergency portal. More...
 
void handleOtaUpdate ()
 Handle over the air firmware update. More...
 

Static Protected Member Functions

static void toggleReceiveFlag ()
 
static void setReceiveFlag (bool value)
 
static bool getReceiveFlag ()
 
static void onPacketReceived ()
 
static bool imAlive (void *)
 
static bool reboot (void *)
 

Protected Attributes

String deviceId
 
DuckLoraduckLora = DuckLora::getInstance()
 
DuckNetduckNet = DuckNet::getInstance()
 

Static Protected Attributes

static volatile bool receivedFlag = false
 

Constructor & Destructor Documentation

◆ Duck() [1/2]

Duck::Duck ( )
inline

Construct a new Duck object.

◆ Duck() [2/2]

Duck::Duck ( String  id)

Construct a new Duck object.

Parameters
ida unique id

◆ ~Duck()

Duck::~Duck ( )
inline

Member Function Documentation

◆ getPassword()

String Duck::getPassword ( )
inline

Get the wifi access point password.

Returns
the wifi access point password as a string.

◆ getReceiveFlag()

static bool Duck::getReceiveFlag ( )
inlinestaticprotected

◆ getSsid()

String Duck::getSsid ( )
inline

Get the access point ssid.

Returns
the wifi access point as a string

◆ getType()

virtual int Duck::getType ( )
protectedpure virtual

◆ handleOtaUpdate()

void Duck::handleOtaUpdate ( )
protected

Handle over the air firmware update.

◆ imAlive()

bool Duck::imAlive ( void *  )
staticprotected

◆ isWifiConnected()

bool Duck::isWifiConnected ( )
inline

Check wifi connection status.

Returns
true if device wifi is connected, false otherwise.

◆ onPacketReceived()

void Duck::onPacketReceived ( void  )
staticprotected

◆ processPortalRequest()

void Duck::processPortalRequest ( )
protected

Handle request from emergency portal.

◆ reboot()

bool Duck::reboot ( void *  )
staticprotected

◆ reconnectWifi()

virtual int Duck::reconnectWifi ( String  ssid,
String  password 
)
inlineprotectedvirtual

◆ run()

virtual void Duck::run ( )
protectedpure virtual

Implement the duck's specific behavior.

This method must be implemented by the Duck's concrete classes such as DuckLink, MamaDuck,...

◆ sendPayloadStandard()

int Duck::sendPayloadStandard ( String  msg = "",
String  topic = "",
String  senderId = "",
String  messageId = "",
String  path = "" 
)

Send a duck LoRa message.

Parameters
msgthe message payload (optional: if not provided, it will be set to an empty string)
topicthe message topic (optional: if not provided, it will be set to "status")
senderIdthe sender id (optional: if not provided, it will be set to the duck device id)
messageIdthe message id (optional: if not provided, a unique id will be generated)
paththe message path to append the device id to (optional: if not provided, the path will only contain the duck's device id)
Returns
DUCK_ERR_NONE if success, an error code otherwise.

◆ setReceiveFlag()

static void Duck::setReceiveFlag ( bool  value)
inlinestaticprotected

◆ setupDns()

int Duck::setupDns ( )

Setup DNS.

Returns
DUCK_ERROR_NONE if successful, an error code otherwise.

◆ setupInternet()

void Duck::setupInternet ( String  ssid,
String  password 
)

Setup internet access.

Parameters
ssidthe ssid of the WiFi network
passwordpassword to join the network

◆ setupOTA()

void Duck::setupOTA ( )

◆ setupRadio()

void Duck::setupRadio ( float  band = CDPCFG_RF_LORA_FREQ,
int  ss = CDPCFG_PIN_LORA_CS,
int  rst = CDPCFG_PIN_LORA_RST,
int  di0 = CDPCFG_PIN_LORA_DIO0,
int  di1 = CDPCFG_PIN_LORA_DIO1,
int  txPower = CDPCFG_RF_LORA_TXPOW 
)

Setup the radio component.

Parameters
bandradio frequency in Mhz (default: 915.0)
ssslave select pin (default CDPCFG_PIN_LORA_CS)
rstreset pin (default: CDPCFG_PIN_LORA_RST)
di0dio0 interrupt pin (default: CDPCFG_PIN_LORA_DIO0)
di1dio1 interrupt pin (default: CDPCFG_PIN_LORA_DIO1)
txPowertransmit power (default: CDPCFG_RF_LORA_TXPOW)

◆ setupSerial()

void Duck::setupSerial ( int  baudRate = 115200)

Setup serial connection.

Parameters
baudRatedefault: 115200

◆ setupWebServer()

void Duck::setupWebServer ( bool  createCaptivePortal = false,
String  html = "" 
)

Setup web server.

The WebServer is used to communicate with the Duck over ad-hoc WiFi connection.

Parameters
createCaptivePortalset to true if Captive WiFi connection is needed. Defaults to false
htmlA string representing custom HTML code used for the portal. Default is an empty string Default portal web page is used if the string is empty

◆ setupWifi()

void Duck::setupWifi ( const char *  ap = "🆘 DUCK EMERGENCY PORTAL")

Setup WiFi access point.

Parameters
accessPointa string representing the access point. Default to "🆘 DUCK EMERGENCY PORTAL"

◆ setupWithDefaults()

virtual void Duck::setupWithDefaults ( String  ssid,
String  password 
)
inlineprotectedvirtual

Setup a duck with default settings.

The default implementation simply initializes the serial interface. It can be overriden by each concrete Duck class implementation.

◆ ssidAvailable()

bool Duck::ssidAvailable ( String  ssid)
inline

Check if the give access point is available.

Parameters
ssidaccess point to check
Returns
true if the access point is available, false otherwise.

◆ startReceive()

int Duck::startReceive ( )
protected

Tell the duck radio to start receiving packets from the mesh network.

Returns
DUCK_ERR_NONE if successful, an error code otherwise

◆ startTransmit()

int Duck::startTransmit ( )
protected

Tell the duck radio to start receiving packets from the mesh network.

Returns
DUCK_ERR_NONE if successful, an error code otherwise

◆ toggleReceiveFlag()

static void Duck::toggleReceiveFlag ( )
inlinestaticprotected

Member Data Documentation

◆ deviceId

String Duck::deviceId
protected

◆ duckLora

DuckLora* Duck::duckLora = DuckLora::getInstance()
protected

◆ duckNet

DuckNet* Duck::duckNet = DuckNet::getInstance()
protected

◆ receivedFlag

volatile bool Duck::receivedFlag = false
staticprotected

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