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.
ESP8266.hpp@24:434330962308, 2016-10-19 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Wed Oct 19 13:23:41 2016 -0500
- Revision:
- 24:434330962308
- Parent:
- 6:b6bafd0a7013
Fixed include guards.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IanBenzMaxim | 1:e1c7c1c636af | 1 | /******************************************************************************* |
IanBenzMaxim | 1:e1c7c1c636af | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
IanBenzMaxim | 1:e1c7c1c636af | 3 | * |
IanBenzMaxim | 1:e1c7c1c636af | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
IanBenzMaxim | 1:e1c7c1c636af | 5 | * copy of this software and associated documentation files (the "Software"), |
IanBenzMaxim | 1:e1c7c1c636af | 6 | * to deal in the Software without restriction, including without limitation |
IanBenzMaxim | 1:e1c7c1c636af | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
IanBenzMaxim | 1:e1c7c1c636af | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
IanBenzMaxim | 1:e1c7c1c636af | 9 | * Software is furnished to do so, subject to the following conditions: |
IanBenzMaxim | 1:e1c7c1c636af | 10 | * |
IanBenzMaxim | 1:e1c7c1c636af | 11 | * The above copyright notice and this permission notice shall be included |
IanBenzMaxim | 1:e1c7c1c636af | 12 | * in all copies or substantial portions of the Software. |
IanBenzMaxim | 1:e1c7c1c636af | 13 | * |
IanBenzMaxim | 1:e1c7c1c636af | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
IanBenzMaxim | 1:e1c7c1c636af | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
IanBenzMaxim | 1:e1c7c1c636af | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IanBenzMaxim | 1:e1c7c1c636af | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
IanBenzMaxim | 1:e1c7c1c636af | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
IanBenzMaxim | 1:e1c7c1c636af | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
IanBenzMaxim | 1:e1c7c1c636af | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
IanBenzMaxim | 1:e1c7c1c636af | 21 | * |
IanBenzMaxim | 1:e1c7c1c636af | 22 | * Except as contained in this notice, the name of Maxim Integrated |
IanBenzMaxim | 1:e1c7c1c636af | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
IanBenzMaxim | 1:e1c7c1c636af | 24 | * Products, Inc. Branding Policy. |
IanBenzMaxim | 1:e1c7c1c636af | 25 | * |
IanBenzMaxim | 1:e1c7c1c636af | 26 | * The mere transfer of this software does not imply any licenses |
IanBenzMaxim | 1:e1c7c1c636af | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
IanBenzMaxim | 1:e1c7c1c636af | 28 | * trademarks, maskwork rights, or any other form of intellectual |
IanBenzMaxim | 1:e1c7c1c636af | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
IanBenzMaxim | 1:e1c7c1c636af | 30 | * ownership rights. |
IanBenzMaxim | 1:e1c7c1c636af | 31 | ******************************************************************************* |
IanBenzMaxim | 1:e1c7c1c636af | 32 | */ |
IanBenzMaxim | 1:e1c7c1c636af | 33 | |
IanBenzMaxim | 24:434330962308 | 34 | #ifndef ESP8266_HPP |
IanBenzMaxim | 24:434330962308 | 35 | #define ESP8266_HPP |
IanBenzMaxim | 1:e1c7c1c636af | 36 | |
IanBenzMaxim | 1:e1c7c1c636af | 37 | #include <string> |
IanBenzMaxim | 1:e1c7c1c636af | 38 | #include <sstream> |
IanBenzMaxim | 1:e1c7c1c636af | 39 | |
IanBenzMaxim | 6:b6bafd0a7013 | 40 | #include "PinNames.h" |
IanBenzMaxim | 6:b6bafd0a7013 | 41 | #include "Serial.h" |
IanBenzMaxim | 6:b6bafd0a7013 | 42 | #include "DigitalOut.h" |
IanBenzMaxim | 1:e1c7c1c636af | 43 | #include "CircularBuffer.h" |
IanBenzMaxim | 1:e1c7c1c636af | 44 | |
IanBenzMaxim | 6:b6bafd0a7013 | 45 | namespace mbed { class Serial; } |
IanBenzMaxim | 6:b6bafd0a7013 | 46 | |
IanBenzMaxim | 1:e1c7c1c636af | 47 | /// Interface to the ESP8266 Wi-Fi module. |
IanBenzMaxim | 1:e1c7c1c636af | 48 | class ESP8266 |
IanBenzMaxim | 1:e1c7c1c636af | 49 | { |
IanBenzMaxim | 1:e1c7c1c636af | 50 | public: |
IanBenzMaxim | 1:e1c7c1c636af | 51 | /// Result of sending an AT command. |
IanBenzMaxim | 1:e1c7c1c636af | 52 | enum CmdResult |
IanBenzMaxim | 1:e1c7c1c636af | 53 | { |
IanBenzMaxim | 1:e1c7c1c636af | 54 | AT_OK = 1, |
IanBenzMaxim | 1:e1c7c1c636af | 55 | AT_FAIL = 0, |
IanBenzMaxim | 1:e1c7c1c636af | 56 | AT_ERROR = -1, |
IanBenzMaxim | 1:e1c7c1c636af | 57 | HardwareError = -2, |
IanBenzMaxim | 1:e1c7c1c636af | 58 | TimeoutError = -3 |
IanBenzMaxim | 1:e1c7c1c636af | 59 | }; |
IanBenzMaxim | 1:e1c7c1c636af | 60 | |
IanBenzMaxim | 1:e1c7c1c636af | 61 | /// ESP8266 Wi-Fi mode. |
IanBenzMaxim | 1:e1c7c1c636af | 62 | enum WifiMode |
IanBenzMaxim | 1:e1c7c1c636af | 63 | { |
IanBenzMaxim | 1:e1c7c1c636af | 64 | station_mode = 1, |
IanBenzMaxim | 1:e1c7c1c636af | 65 | softAP_mode = 2, |
IanBenzMaxim | 1:e1c7c1c636af | 66 | softAP_station_mode = 3 |
IanBenzMaxim | 1:e1c7c1c636af | 67 | }; |
IanBenzMaxim | 1:e1c7c1c636af | 68 | |
IanBenzMaxim | 1:e1c7c1c636af | 69 | /// Connection type. |
IanBenzMaxim | 1:e1c7c1c636af | 70 | enum ConnType |
IanBenzMaxim | 1:e1c7c1c636af | 71 | { |
IanBenzMaxim | 1:e1c7c1c636af | 72 | TCP, |
IanBenzMaxim | 1:e1c7c1c636af | 73 | UDP |
IanBenzMaxim | 1:e1c7c1c636af | 74 | }; |
IanBenzMaxim | 1:e1c7c1c636af | 75 | |
IanBenzMaxim | 1:e1c7c1c636af | 76 | /// Recovery time between Send Data operation as specified by datasheet. |
IanBenzMaxim | 1:e1c7c1c636af | 77 | static const unsigned int sendDataRecoveryTimeMs = 1000; |
IanBenzMaxim | 1:e1c7c1c636af | 78 | |
IanBenzMaxim | 1:e1c7c1c636af | 79 | /// Builds command strings for the ESP8266 with proper formatting. |
IanBenzMaxim | 1:e1c7c1c636af | 80 | class CmdBuilder |
IanBenzMaxim | 1:e1c7c1c636af | 81 | { |
IanBenzMaxim | 1:e1c7c1c636af | 82 | public: |
IanBenzMaxim | 1:e1c7c1c636af | 83 | /// @param cmd Command of the format "AT+[cmd]". |
IanBenzMaxim | 1:e1c7c1c636af | 84 | CmdBuilder(const std::string & cmd = ""); |
IanBenzMaxim | 1:e1c7c1c636af | 85 | |
IanBenzMaxim | 1:e1c7c1c636af | 86 | /// Clear all arguments. |
IanBenzMaxim | 1:e1c7c1c636af | 87 | /// @param cmd Command of the format "AT+[cmd]". |
IanBenzMaxim | 1:e1c7c1c636af | 88 | void clear(const std::string & cmd); |
IanBenzMaxim | 1:e1c7c1c636af | 89 | |
IanBenzMaxim | 1:e1c7c1c636af | 90 | /// Append an argument using the default string conversion for that type. |
IanBenzMaxim | 1:e1c7c1c636af | 91 | /// @param arg Argument to append to the command. |
IanBenzMaxim | 1:e1c7c1c636af | 92 | template <typename T> void addRawArgument(const T & arg) |
IanBenzMaxim | 1:e1c7c1c636af | 93 | { |
IanBenzMaxim | 1:e1c7c1c636af | 94 | cmdStream << ((numArgs == 0) ? "=" : ",") << arg; |
IanBenzMaxim | 1:e1c7c1c636af | 95 | numArgs++; |
IanBenzMaxim | 1:e1c7c1c636af | 96 | } |
IanBenzMaxim | 1:e1c7c1c636af | 97 | |
IanBenzMaxim | 1:e1c7c1c636af | 98 | /// Append a string argument with proper quoting. |
IanBenzMaxim | 1:e1c7c1c636af | 99 | /// @param arg Argument to append to the command. |
IanBenzMaxim | 1:e1c7c1c636af | 100 | void addStringArgument(const std::string & arg); |
IanBenzMaxim | 1:e1c7c1c636af | 101 | |
IanBenzMaxim | 1:e1c7c1c636af | 102 | /// Create a string suitable for use with sendCommand(). |
IanBenzMaxim | 1:e1c7c1c636af | 103 | /// @returns The formatted command string. |
IanBenzMaxim | 1:e1c7c1c636af | 104 | std::string str() const; |
IanBenzMaxim | 1:e1c7c1c636af | 105 | |
IanBenzMaxim | 1:e1c7c1c636af | 106 | private: |
IanBenzMaxim | 1:e1c7c1c636af | 107 | int numArgs; |
IanBenzMaxim | 1:e1c7c1c636af | 108 | std::ostringstream cmdStream; |
IanBenzMaxim | 1:e1c7c1c636af | 109 | }; |
IanBenzMaxim | 1:e1c7c1c636af | 110 | |
IanBenzMaxim | 1:e1c7c1c636af | 111 | /// @{ |
IanBenzMaxim | 1:e1c7c1c636af | 112 | /// Default instance support for use with mbed Sockets. |
IanBenzMaxim | 1:e1c7c1c636af | 113 | static void setDefaultInstance(ESP8266 * const instance); |
IanBenzMaxim | 1:e1c7c1c636af | 114 | static ESP8266** getDefaultInstance(); |
IanBenzMaxim | 1:e1c7c1c636af | 115 | /// @} |
IanBenzMaxim | 1:e1c7c1c636af | 116 | |
IanBenzMaxim | 1:e1c7c1c636af | 117 | /// @param tx Transmit pin from mbed to ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 118 | /// @param rx Receive pin from ESP8266 to mbed. |
IanBenzMaxim | 1:e1c7c1c636af | 119 | /// @param rst Reset pin on ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 120 | /// @param CH_PD Power-down pin on ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 121 | /// @param baud Baud rate that the ESP8266 is using. |
IanBenzMaxim | 1:e1c7c1c636af | 122 | /// @param debugMsgIntf Optional serial interface for debugging messages. |
IanBenzMaxim | 6:b6bafd0a7013 | 123 | ESP8266(const PinName tx, const PinName rx, const PinName rst, const PinName CH_PD, const int baud, mbed::Serial * debugMsgIntf = NULL); |
IanBenzMaxim | 1:e1c7c1c636af | 124 | ~ESP8266(); |
IanBenzMaxim | 1:e1c7c1c636af | 125 | |
IanBenzMaxim | 1:e1c7c1c636af | 126 | /// Reset the ESP8266 via the hardware reset pin. |
IanBenzMaxim | 1:e1c7c1c636af | 127 | void reset(); |
IanBenzMaxim | 1:e1c7c1c636af | 128 | |
IanBenzMaxim | 1:e1c7c1c636af | 129 | // Update the baud rate for the ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 130 | void setBaud(int baud) { AT_intf.baud(baud); } |
IanBenzMaxim | 1:e1c7c1c636af | 131 | |
IanBenzMaxim | 1:e1c7c1c636af | 132 | /// @{ |
IanBenzMaxim | 1:e1c7c1c636af | 133 | /// Control if the ESP8266 is powered via the hardware power-down pin. |
IanBenzMaxim | 1:e1c7c1c636af | 134 | bool powered() const; |
IanBenzMaxim | 1:e1c7c1c636af | 135 | void setPowered(bool powered); |
IanBenzMaxim | 1:e1c7c1c636af | 136 | /// @} |
IanBenzMaxim | 1:e1c7c1c636af | 137 | |
IanBenzMaxim | 1:e1c7c1c636af | 138 | /// Perform a self-test on the ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 139 | CmdResult performSelfTest(); |
IanBenzMaxim | 1:e1c7c1c636af | 140 | |
IanBenzMaxim | 1:e1c7c1c636af | 141 | /// Set the current Wi-Fi mode. |
IanBenzMaxim | 1:e1c7c1c636af | 142 | CmdResult setCurrentWifiMode(const WifiMode mode); |
IanBenzMaxim | 1:e1c7c1c636af | 143 | |
IanBenzMaxim | 1:e1c7c1c636af | 144 | /// Join a Wi-Fi access point. |
IanBenzMaxim | 1:e1c7c1c636af | 145 | /// @param ssid Network SSID to connect to. |
IanBenzMaxim | 1:e1c7c1c636af | 146 | /// @param pwd Network password. |
IanBenzMaxim | 1:e1c7c1c636af | 147 | /// @param bssid Optional network BSSID. |
IanBenzMaxim | 1:e1c7c1c636af | 148 | CmdResult joinCurrentAccessPoint(const std::string & ssid, const std::string & pwd, const std::string & bssid = ""); |
IanBenzMaxim | 1:e1c7c1c636af | 149 | |
IanBenzMaxim | 1:e1c7c1c636af | 150 | /// Quit the current access point. |
IanBenzMaxim | 1:e1c7c1c636af | 151 | CmdResult quitAccessPoint(); |
IanBenzMaxim | 1:e1c7c1c636af | 152 | |
IanBenzMaxim | 1:e1c7c1c636af | 153 | /// Set the maximum WiFi tranmission power. |
IanBenzMaxim | 1:e1c7c1c636af | 154 | /// @param power_dBm Power in dBm valid from 0 to 20.5 in 0.25 dBm increments. |
IanBenzMaxim | 1:e1c7c1c636af | 155 | CmdResult setMaxRFTXPower(const float power_dBm); |
IanBenzMaxim | 1:e1c7c1c636af | 156 | |
IanBenzMaxim | 1:e1c7c1c636af | 157 | /// Ping a host via the current access point. |
IanBenzMaxim | 1:e1c7c1c636af | 158 | /// @param IP IP address or resolvable hostname. |
IanBenzMaxim | 1:e1c7c1c636af | 159 | CmdResult ping(const std::string & IP); |
IanBenzMaxim | 1:e1c7c1c636af | 160 | |
IanBenzMaxim | 1:e1c7c1c636af | 161 | /// Open a connection to a host via the current access point. |
IanBenzMaxim | 1:e1c7c1c636af | 162 | /// @param type TCP or UPD connection. |
IanBenzMaxim | 1:e1c7c1c636af | 163 | /// @param remoteIP IP address or resolvable hostname to connect to. |
IanBenzMaxim | 1:e1c7c1c636af | 164 | /// @param remotePort Port on the host to connect to. |
IanBenzMaxim | 1:e1c7c1c636af | 165 | CmdResult openConnection(const ConnType type, const std::string & remoteIP, const unsigned int remotePort); |
IanBenzMaxim | 1:e1c7c1c636af | 166 | |
IanBenzMaxim | 1:e1c7c1c636af | 167 | /// Close the connection to the current host. |
IanBenzMaxim | 1:e1c7c1c636af | 168 | CmdResult closeConnection(); |
IanBenzMaxim | 1:e1c7c1c636af | 169 | |
IanBenzMaxim | 1:e1c7c1c636af | 170 | /// Send data to the currently connected host. |
IanBenzMaxim | 1:e1c7c1c636af | 171 | /// @param data May be in text or binary form. |
IanBenzMaxim | 1:e1c7c1c636af | 172 | CmdResult sendData(const std::string & data); |
IanBenzMaxim | 1:e1c7c1c636af | 173 | |
IanBenzMaxim | 1:e1c7c1c636af | 174 | /// Send an AT command to the ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 175 | /// @param cmd Formatted command to send. |
IanBenzMaxim | 1:e1c7c1c636af | 176 | CmdResult sendCommand(const CmdBuilder & cmd); |
IanBenzMaxim | 1:e1c7c1c636af | 177 | |
IanBenzMaxim | 1:e1c7c1c636af | 178 | /// Check if received IP data is available in the buffer. |
IanBenzMaxim | 1:e1c7c1c636af | 179 | /// @note Allow some processing delay to happen between calls to this function. |
IanBenzMaxim | 1:e1c7c1c636af | 180 | /// @returns True if data is available. |
IanBenzMaxim | 1:e1c7c1c636af | 181 | bool recvIpDataReadable(); |
IanBenzMaxim | 1:e1c7c1c636af | 182 | /// Get the next character of received IP data from the buffer. |
IanBenzMaxim | 1:e1c7c1c636af | 183 | char getcRecvIpData(); |
IanBenzMaxim | 1:e1c7c1c636af | 184 | /// Clear all received data from the buffer. |
IanBenzMaxim | 1:e1c7c1c636af | 185 | void clearRecvData(); |
IanBenzMaxim | 1:e1c7c1c636af | 186 | |
IanBenzMaxim | 1:e1c7c1c636af | 187 | private: |
IanBenzMaxim | 1:e1c7c1c636af | 188 | static ESP8266 * defaultInstance; ///< Default instance support for use with mbed Sockets. |
IanBenzMaxim | 1:e1c7c1c636af | 189 | |
IanBenzMaxim | 6:b6bafd0a7013 | 190 | mbed::Serial AT_intf; |
IanBenzMaxim | 6:b6bafd0a7013 | 191 | mbed::DigitalOut resetPin; |
IanBenzMaxim | 6:b6bafd0a7013 | 192 | mutable mbed::DigitalOut powerDownPin; ///< @note Mark as mutable for use in powered(). |
IanBenzMaxim | 6:b6bafd0a7013 | 193 | mbed::CircularBuffer<char, 1024> recvIpDataBuffer; ///< Received IP data buffer. |
IanBenzMaxim | 6:b6bafd0a7013 | 194 | mbed::Serial * debugMsg; |
IanBenzMaxim | 1:e1c7c1c636af | 195 | volatile bool parseRecvReset; ///< Indicates when AT interface received data parsers should be reset. |
IanBenzMaxim | 1:e1c7c1c636af | 196 | |
IanBenzMaxim | 1:e1c7c1c636af | 197 | /// Send raw AT data to the ESP8266. |
IanBenzMaxim | 1:e1c7c1c636af | 198 | /// @param cmdString Data to send. |
IanBenzMaxim | 1:e1c7c1c636af | 199 | /// @param expectEcho True if the ESP8266 will echo sent data back. |
IanBenzMaxim | 1:e1c7c1c636af | 200 | CmdResult send_AT_data(const std::string & cmdString, const bool expectEcho); |
IanBenzMaxim | 1:e1c7c1c636af | 201 | |
IanBenzMaxim | 1:e1c7c1c636af | 202 | /// Attempts to read an entire line terminated with \r\n from the AT interface. |
IanBenzMaxim | 1:e1c7c1c636af | 203 | /// \r will be preserved in the final string and \n will be stripped. |
IanBenzMaxim | 1:e1c7c1c636af | 204 | /// @param line Buffer to store received characters in. |
IanBenzMaxim | 1:e1c7c1c636af | 205 | /// @returns True if an entire line was read. |
IanBenzMaxim | 1:e1c7c1c636af | 206 | bool read_line(std::string & line); |
IanBenzMaxim | 1:e1c7c1c636af | 207 | |
IanBenzMaxim | 1:e1c7c1c636af | 208 | /// Callback for when data is received on the AT interface. |
IanBenzMaxim | 1:e1c7c1c636af | 209 | void recv_AT_data_cb(); |
IanBenzMaxim | 1:e1c7c1c636af | 210 | /// Parse the next character received on the AT interface checking for valid IP data. |
IanBenzMaxim | 1:e1c7c1c636af | 211 | void parseRecvIpData(const char received); |
IanBenzMaxim | 1:e1c7c1c636af | 212 | /// Parse the next character receive on the AT interface for the connection closed message. |
IanBenzMaxim | 1:e1c7c1c636af | 213 | void parseRecvConnClosedMsg(const char received); |
IanBenzMaxim | 1:e1c7c1c636af | 214 | |
IanBenzMaxim | 1:e1c7c1c636af | 215 | /// Print a message on the debugging interface if setup. |
IanBenzMaxim | 1:e1c7c1c636af | 216 | /// @param message Null terminated string. |
IanBenzMaxim | 1:e1c7c1c636af | 217 | void printDbgMsg(const char * message); |
IanBenzMaxim | 1:e1c7c1c636af | 218 | }; |
IanBenzMaxim | 1:e1c7c1c636af | 219 | |
IanBenzMaxim | 1:e1c7c1c636af | 220 | #endif |