Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DISCO_L475VG_IOT01A_wifi mbed stm-spirit1-rf-driver
MQTT_wifi.h
00001 #include <string> 00002 00003 #include "wifi.h" 00004 00005 00006 class MQTT_wifi 00007 { 00008 public: 00009 MQTT_wifi() { 00010 } 00011 00012 int connect(char* hostname, int port, int timeout=1000) { 00013 00014 uint8_t addr[4]; 00015 if (WIFI_GetHostAddress(hostname, addr) != WIFI_STATUS_OK) { 00016 return -1; 00017 } 00018 00019 if (WIFI_OpenClientConnection(0, WIFI_TCP_PROTOCOL, "TCP_CLIENT", addr, port, 100) != WIFI_STATUS_OK) { 00020 return -1; 00021 } 00022 00023 socket = 0; 00024 return socket; 00025 } 00026 00027 int read(unsigned char* buffer, int len, int timeout) { 00028 uint16_t read_len = -1; 00029 if(WIFI_ReceiveData(socket, buffer, len, &read_len, timeout) == WIFI_STATUS_OK) { 00030 return read_len; 00031 } 00032 00033 return -1; 00034 } 00035 00036 int write(unsigned char* buffer, int len, int timeout) { 00037 uint16_t sent_len = -1; 00038 if(WIFI_SendData(socket, buffer, len, &sent_len, timeout) == WIFI_STATUS_OK) { 00039 return sent_len; 00040 } 00041 00042 return -1; 00043 } 00044 00045 00046 00047 private: 00048 int socket; 00049 00050 };
Generated on Sat Jul 30 2022 04:21:29 by
1.7.2