b_mod_wifi

数据结构

typedef void *bWifiHandle_t;
typedef void *bWifiConnHandle_t;

typedef struct
{
    char    ssid[64];
    char    passwd[64];
    uint8_t encryption;
} bWifiApInfo_t;

typedef struct
{
    char     broker[64];
    uint16_t port;
    char     device_id[64];
    char     user[64];
    char     passwd[64];
} bWifiMqtt_t;

typedef struct
{
    char     topic[64];
    uint8_t *pbuf;
    uint16_t len;
    void (*release)(void *);
} bWifiMqttData_t;

typedef enum
{
    WIFI_EVT_STA_MODE,
    WIFI_EVT_STA_ERR,
    WIFI_EVT_AP_MODE,
    WIFI_EVT_AP_ERR,
    WIFI_EVT_AP_STA_MODE,
    WIFI_EVT_AP_STA_ERR,
    WIFI_EVT_JOINAP_OK,
    WIFI_EVT_JOINAP_ERR,
    WIFI_EVT_PING_OK,
    WIFI_EVT_PING_ERR,
    WIFI_EVT_SETUP_TCPSERVER_OK,
    WIFI_EVT_SETUP_TCPSERVER_ERR,
    WIFI_EVT_DATA_READY,
    WIFI_EVT_MQTT_CONN_OK,
    WIFI_EVT_MQTT_CONN_ERR,
    WIFI_EVT_MQTT_SUB_OK,
    WIFI_EVT_MQTT_SUB_ERR,
    WIFI_EVT_MQTT_PUB_OK,
    WIFI_EVT_MQTT_PUB_ERR,
    WIFI_EVT_MQTT_DATA,
} bWifiEvent_t;

typedef void (*bWifiEventHandle_t)(bWifiHandle_t handle, bWifiEvent_t evt, void *arg);

接口介绍

int bWifiInit(void);

bWifiHandle_t bWifiUp(uint32_t dev_no, bWifiEventHandle_t cb);
int           bWifiDown(bWifiHandle_t handle);
/**
 * \brief 设置WIFI的工作模式
 * \param handle \ref bWifiUp
 * \param mode WIFI_MODE_STA、WIFI_MODE_AP、WIFI_MODE_AP_STA
 * \param pinfo STA模式可以为空,其他模式需要设定AP信息
 */
int bWifiSetMode(bWifiHandle_t handle, uint8_t mode, const bWifiApInfo_t *pinfo);
int bWifiJoinAp(bWifiHandle_t handle, const bWifiApInfo_t *pinfo);
int bWifiPing(bWifiHandle_t handle);

bWifiConnHandle_t bWifiSetupServer(bWifiHandle_t handle, uint8_t type, uint16_t port);
bWifiConnHandle_t bWifiConnectServer(bWifiHandle_t handle, uint8_t type, const char *ip,
                                     uint16_t port);

int bWifiConnClose(bWifiConnHandle_t conn);
int bWifiConnSend(bWifiConnHandle_t conn, uint8_t *pbuf, uint16_t len);
int bWifiConnRead(bWifiConnHandle_t conn, uint8_t *pbuf, uint16_t len);

int bWifiMqttConnect(bWifiHandle_t handle, bWifiMqtt_t *mqtt);
int bWifiMqttSub(bWifiHandle_t handle, const char *topic, uint8_t qos);
int bWifiMqttPub(bWifiHandle_t handle, const char *topic, uint8_t qos, uint8_t *pbuf, uint16_t len);

使用例子

//具体查看例程仓库代码