MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification
Dependencies: MaximInterface mbed
The MAXREFDES143# is an Internet of Things (IoT) embedded security reference design, built to protect an industrial sensing node by means of authentication and notification to a web server. The hardware includes a peripheral module representing a protected sensor node monitoring operating temperature and remaining life of a filter (simulated through ambient light sensing) and an mbed shield representing a controller node responsible for monitoring one or more sensor nodes. The design is hierarchical with each controller node communicating data from connected sensor nodes to a web server that maintains a centralized log and dispatches notifications as necessary. The mbed shield contains a Wi-Fi module, a DS2465 coprocessor with 1-Wire® master function, an LCD, LEDs, and pushbuttons. The protected sensor node contains a DS28E15 authenticator, a DS7505 temperature sensor, and a MAX44009 light sensor. The mbed shield communicates to a web server by the onboard Wi-Fi module and to the protected sensor node with I2C and 1-Wire. The MAXREFDES143# is equipped with a standard shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The simplicity of this design enables rapid integration into any star-topology IoT network requiring the heightened security with low overhead provided by the SHA-256 symmetric-key algorithm.
More information about the MAXREFDES143# is available on the Maxim Integrated website.
Diff: ESP8266.hpp
- Revision:
- 32:0a09505a656d
- Parent:
- 30:0784010d6975
diff -r 7b10bcb3e0fc -r 0a09505a656d ESP8266.hpp
--- a/ESP8266.hpp Tue Apr 04 14:10:48 2017 -0500
+++ b/ESP8266.hpp Mon Nov 06 17:34:13 2017 -0600
@@ -28,146 +28,134 @@
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
-*******************************************************************************
-*/
+*******************************************************************************/
#ifndef ESP8266_HPP
#define ESP8266_HPP
#include <string>
#include <sstream>
-
-#include "PinNames.h"
-#include "Serial.h"
-#include "DigitalOut.h"
-#include "CircularBuffer.h"
-
-namespace mbed { class Serial; }
+#include <PinNames.h>
+#include <Serial.h>
+#include <DigitalOut.h>
+#include <CircularBuffer.h>
/// Interface to the ESP8266 Wi-Fi module.
-class ESP8266
-{
+class ESP8266 {
public:
/// Result of sending an AT command.
- enum CmdResult
- {
+ enum CmdResult {
AT_OK = 1,
AT_FAIL = 0,
AT_ERROR = -1,
HardwareError = -2,
TimeoutError = -3
};
-
+
/// ESP8266 Wi-Fi mode.
- enum WifiMode
- {
- station_mode = 1,
- softAP_mode = 2,
- softAP_station_mode = 3
- };
-
+ enum WifiMode { station_mode = 1, softAP_mode = 2, softAP_station_mode = 3 };
+
/// Connection type.
- enum ConnType
- {
- TCP,
- UDP
- };
-
+ enum ConnType { TCP, UDP };
+
/// Recovery time between Send Data operation as specified by datasheet.
- static const unsigned int sendDataRecoveryTimeMs = 1000;
-
+ static const int sendDataRecoveryTimeMs = 1000;
+
/// Builds command strings for the ESP8266 with proper formatting.
- class CmdBuilder
- {
+ class CmdBuilder {
public:
/// @param cmd Command of the format "AT+[cmd]".
CmdBuilder(const std::string & cmd = "");
-
+
/// Clear all arguments.
/// @param cmd Command of the format "AT+[cmd]".
void clear(const std::string & cmd);
-
+
/// Append an argument using the default string conversion for that type.
/// @param arg Argument to append to the command.
- template <typename T> void addRawArgument(const T & arg)
- {
+ template <typename T> void addRawArgument(const T & arg) {
cmdStream << ((numArgs == 0) ? "=" : ",") << arg;
numArgs++;
}
-
+
/// Append a string argument with proper quoting.
/// @param arg Argument to append to the command.
void addStringArgument(const std::string & arg);
-
+
/// Create a string suitable for use with sendCommand().
/// @returns The formatted command string.
std::string str() const;
-
+
private:
int numArgs;
std::ostringstream cmdStream;
};
-
+
/// @param tx Transmit pin from mbed to ESP8266.
/// @param rx Receive pin from ESP8266 to mbed.
/// @param rst Reset pin on ESP8266.
/// @param CH_PD Power-down pin on ESP8266.
/// @param baud Baud rate that the ESP8266 is using.
/// @param debugMsgIntf Optional serial interface for debugging messages.
- ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, mbed::Serial * debugMsgIntf = NULL);
-
+ ESP8266(const PinName tx, const PinName rx, const PinName rst,
+ const PinName CH_PD, const int baud,
+ mbed::Serial * debugMsgIntf = NULL);
+
/// Reset the ESP8266 via the hardware reset pin.
void reset();
-
+
// Update the baud rate for the ESP8266.
void setBaud(int baud) { AT_intf.baud(baud); }
-
+
/// @{
/// Control if the ESP8266 is powered via the hardware power-down pin.
bool powered() const;
void setPowered(bool powered);
/// @}
-
+
/// Perform a self-test on the ESP8266.
CmdResult performSelfTest();
-
+
/// Set the current Wi-Fi mode.
CmdResult setCurrentWifiMode(const WifiMode mode);
-
+
/// Join a Wi-Fi access point.
/// @param ssid Network SSID to connect to.
/// @param pwd Network password.
/// @param bssid Optional network BSSID.
- CmdResult joinCurrentAccessPoint(const std::string & ssid, const std::string & pwd, const std::string & bssid = "");
-
+ CmdResult joinCurrentAccessPoint(const std::string & ssid,
+ const std::string & pwd,
+ const std::string & bssid = "");
+
/// Quit the current access point.
CmdResult quitAccessPoint();
-
+
/// Set the maximum WiFi tranmission power.
/// @param power_dBm Power in dBm valid from 0 to 20.5 in 0.25 dBm increments.
CmdResult setMaxRFTXPower(const float power_dBm);
-
+
/// Ping a host via the current access point.
/// @param IP IP address or resolvable hostname.
CmdResult ping(const std::string & IP);
-
+
/// Open a connection to a host via the current access point.
/// @param type TCP or UPD connection.
/// @param remoteIP IP address or resolvable hostname to connect to.
/// @param remotePort Port on the host to connect to.
- CmdResult openConnection(const ConnType type, const std::string & remoteIP, const unsigned int remotePort);
-
+ CmdResult openConnection(const ConnType type, const std::string & remoteIP,
+ const unsigned int remotePort);
+
/// Close the connection to the current host.
CmdResult closeConnection();
-
+
/// Send data to the currently connected host.
/// @param data May be in text or binary form.
CmdResult sendData(const std::string & data);
-
+
/// Send an AT command to the ESP8266.
/// @param cmd Formatted command to send.
CmdResult sendCommand(const CmdBuilder & cmd);
-
+
/// Check if received IP data is available in the buffer.
/// @note Allow some processing delay to happen between calls to this function.
/// @returns True if data is available.
@@ -176,33 +164,37 @@
char getcRecvIpData();
/// Clear all received data from the buffer.
void clearRecvData();
-
-private:
+
+private:
mbed::Serial AT_intf;
mbed::DigitalOut resetPin;
- mutable mbed::DigitalOut powerDownPin; ///< @note Mark as mutable for use in powered().
- mbed::CircularBuffer<char, 1024> recvIpDataBuffer; ///< Received IP data buffer.
+ /// @note Mark as mutable for use in powered().
+ mutable mbed::DigitalOut powerDownPin;
+ /// Received IP data buffer.
+ mbed::CircularBuffer<char, 1024> recvIpDataBuffer;
mbed::Serial * debugMsg;
- volatile bool parseRecvReset; ///< Indicates when AT interface received data parsers should be reset.
-
+ /// Indicates when AT interface received data parsers should be reset.
+ volatile bool parseRecvReset;
+
/// Send raw AT data to the ESP8266.
/// @param cmdString Data to send.
/// @param expectEcho True if the ESP8266 will echo sent data back.
CmdResult send_AT_data(const std::string & cmdString, const bool expectEcho);
-
+
/// Attempts to read an entire line terminated with \r\n from the AT interface.
/// \r will be preserved in the final string and \n will be stripped.
/// @param line Buffer to store received characters in.
/// @returns True if an entire line was read.
bool read_line(std::string & line);
-
+
/// Callback for when data is received on the AT interface.
void recv_AT_data_cb();
/// Parse the next character received on the AT interface checking for valid IP data.
void parseRecvIpData(const char received);
- /// Parse the next character receive on the AT interface for the connection closed message.
+ /// Parse the next character receive on the AT interface for the connection
+ /// closed message.
void parseRecvConnClosedMsg(const char received);
-
+
/// Print a message on the debugging interface if setup.
/// @param message Null terminated string.
void printDbgMsg(const char * message);
MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification