Example of AWS IoT connection and Web Dashboard thru STM32 Nucleo evaluation board and mbed OS.
Dependencies: X_NUCLEO_IKS01A1 mbed FP MQTTPacket DnsQuery ATParser
SPWFSA01.h
00001 /* SPWFInterface Example 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SPWFSA01_H 00018 #define SPWFSA01_H 00019 00020 #include "ATParser.h" 00021 00022 /** SPWFSA01Interface class. 00023 This is an interface to a SPWFSA01 module. 00024 */ 00025 class SPWFSA01 00026 { 00027 public: 00028 00029 SPWFSA01(PinName tx, PinName rx, PinName reset=NC, PinName wakeup=NC, bool debug=false); 00030 00031 /** 00032 * Init the SPWFSA01 00033 * 00034 * @param mode mode in which to startup 00035 * @return true only if SPWFSA01 has started up correctly 00036 */ 00037 bool startup(int mode); 00038 00039 void waitSPWFReady(void); 00040 /** 00041 * Reset SPWFSA01 00042 * 00043 * @return true only if SPWFSA01 resets successfully 00044 */ 00045 bool reset(void); 00046 00047 bool hw_reset(void); 00048 00049 /** 00050 * Enable/Disable DHCP 00051 * 00052 * @param mode mode of DHCP 2-softAP, 1-on, 0-off 00053 * @return true only if SPWFSA01 enables/disables DHCP successfully 00054 */ 00055 bool dhcp(int mode); 00056 00057 /** 00058 * Connect SPWFSA01 to AP 00059 * 00060 * @param ap the name of the AP 00061 * @param passPhrase the password of AP 00062 * @param securityMode the security mode of AP (WPA/WPA2, WEP, Open) 00063 * @return true only if SPWFSA01 is connected successfully 00064 */ 00065 bool connect(const char *ap, const char *passPhrase, int securityMode); 00066 00067 /** 00068 * Disconnect SPWFSA01 from AP 00069 * 00070 * @return true only if SPWFSA01 is disconnected successfully 00071 */ 00072 bool disconnect(void); 00073 00074 /** 00075 * Get the IP address of SPWFSA01 00076 * 00077 * @return null-teriminated IP address or null if no IP address is assigned 00078 */ 00079 const char *getIPAddress(void); 00080 00081 /** 00082 * Get the MAC address of SPWFSA01 00083 * 00084 * @return null-terminated MAC address or null if no MAC address is assigned 00085 */ 00086 const char *getMACAddress(void); 00087 00088 /** 00089 * Check if SPWFSA01 is conenected 00090 * 00091 * @return true only if the chip has an IP address 00092 */ 00093 bool isConnected(void); 00094 00095 /** 00096 * @brief wifi_socket_client_security 00097 * Set the security certificates and key for secure socket (TLS) 00098 * @param None 00099 * @retval return nonzero in case of error 00100 */ 00101 int setSocketClientSecurity(uint8_t* tls_mode, uint8_t* root_ca_server, uint8_t* client_cert, uint8_t* client_key, uint8_t* client_domain, uint32_t tls_epoch_time); 00102 00103 /** 00104 * Open a socketed connection 00105 * 00106 * @param type the type of socket to open "u" (UDP) or "t" (TCP) 00107 * @param id id to get the new socket number, valid 0-7 00108 * @param port port to open connection with 00109 * @param addr the IP address of the destination 00110 * @return true only if socket opened successfully 00111 */ 00112 bool open(const char *type, int* id, const char* addr, int port); 00113 00114 /** 00115 * Sends data to an open socket 00116 * 00117 * @param id id of socket to send to 00118 * @param data data to be sent 00119 * @param amount amount of data to be sent - max 1024 00120 * @return true only if data sent successfully 00121 */ 00122 bool send(int id, const void *data, uint32_t amount); 00123 00124 /** 00125 * Receives data from an open socket 00126 * 00127 * @param id id to receive from 00128 * @param data placeholder for returned information 00129 * @param amount number of bytes to be received 00130 * @return the number of bytes received 00131 */ 00132 int32_t recv(int id, void *data, uint32_t amount); 00133 00134 /** 00135 * Closes a socket 00136 * 00137 * @param id id of socket to close, valid only 0-4 00138 * @return true only if socket is closed successfully 00139 */ 00140 bool close(int id); 00141 00142 00143 /** 00144 * Checks if data is available 00145 */ 00146 bool readable(); 00147 00148 /** 00149 * Checks if data can be written 00150 */ 00151 bool writeable(); 00152 00153 /** Sets debug mode */ 00154 inline void set_debug(bool state) { dbg_on = state;_parser.debugOn(state);}; 00155 00156 private: 00157 BufferedSerial _serial; 00158 ATParser _parser; 00159 DigitalInOut _wakeup; 00160 DigitalInOut _reset; 00161 char _ip_buffer[16]; 00162 char _mac_buffer[18]; 00163 bool dbg_on; 00164 // int _timeout; // FIXME LICIO we have "virtual" socket tmo, module socket tmo, 00165 // AT parser tmo, recv/send tmo, actually used the NetworksocketAPI socket tmo 00166 unsigned int _recv_timeout; // see SO_RCVTIMEO setsockopt 00167 unsigned int _send_timeout; // see SO_SNDTIMEO setsockopt 00168 unsigned int socket_closed; 00169 }; 00170 00171 #endif //SPWFSA01_H
Generated on Wed Jul 13 2022 20:28:49 by 1.7.2