Skip to content

Commit

Permalink
feat: implement an windows sample
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsan committed Nov 2, 2023
1 parent 7529682 commit cc39e28
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/win32/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly

cmake_minimum_required(VERSION 3.5)

set(CIOT_DIR ../../)

project(ciot_win32)

FILE(GLOB_RECURSE infa_src ${CIOT_DIR}/main/infra/mg/*)
FILE(GLOB_RECURSE ifaces_src ${CIOT_DIR}/main/interfaces/*)
FILE(GLOB_RECURSE mg_src ${CIOT_DIR}/main/mongoose/*)
FILE(GLOB app_src ${CIOT_DIR}/main/*)

include_directories(
${CIOT_DIR}/main/types
${CIOT_DIR}/main/infra
${CIOT_DIR}/main/interfaces
${CIOT_DIR}/main/mongoose
${CIOT_DIR}/main
)

add_executable(${PROJECT_NAME}
${infa_src}
${ifaces_src}
${mg_src}
${app_src}
main.c
)

target_link_libraries(${PROJECT_NAME} ws2_32)
73 changes: 73 additions & 0 deletions examples/win32/ciot_custom_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* @file ciot_custom_config.h
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2023-11-02
*
* @copyright Copyright (c) 2023
*
*/

#ifndef __CIOT_CUSTOM_CONFIG__H__
#define __CIOT_CUSTOM_CONFIG__H__

#define CIOT_CONFIG_FIRMWARE_VER \
{ \
0, 3, 0 \
}
#define CIOT_CONFIG_HARDWARE_NAME "CIOT BOARD"

#define CIOT_CONFIG_FEATURE_UART 1 ///!< Enable UART
#define CIOT_CONFIG_FEATURE_USB 0 ///!< Enable USB
#define CIOT_CONFIG_FEATURE_BLE 0 ///!< Enable Bluetooth
#define CIOT_CONFIG_FEATURE_ETHERNET 0 ///!< Enable Ethernet
#define CIOT_CONFIG_FEATURE_WIFI 0 ///!< Enable WiFi
#define CIOT_CONFIG_FEATURE_NTP 0 ///!< Enable NTP
#define CIOT_CONFIG_FEATURE_OTA 0 ///!< Enable OTA
#define CIOT_CONFIG_FEATURE_HTTPS 1 ///!< Enable HTTP Server
#define CIOT_CONFIG_FEATURE_HTTPC 1 ///!< Enable HTTP Client
#define CIOT_CONFIG_FEATURE_MQTTC 1 ///!< Enable MQTT Client
#define CIOT_CONFIG_MESSAGE_LEN 330 ///!< CIOT expected message size

#define CIOT_CONFIG_UART_RX_BUF_SIZE 256
#define CIOT_CONFIG_UART_TX_BUF_SIZE 256
#define CIOT_CONFIG_UART_BAUD 115200
#define CIOT_CONFIG_UART_PORT 8

#define CIOT_CONFIG_HTTPC_TIMEOUT 5000

// #define CIOT_CONFIG_UART_QUEUE_SIZE 20
// #define CIOT_CONFIG_UART_TASK_SIZE 2048
// #define CIOT_CONFIG_UART_TASK_PRIO 12
// #define CIOT_CONFIG_UART_TASK_CORE 0

// #define CIOT_CONFIG_ETH_PHY_KSZ8081 1
// #define CIOT_CONFIG_ETH_PHY_NEW(x) esp_eth_phy_new_ksz80xx(&x)
// #define CIOT_CONFIG_ETH_PHY_ADDR 0
// #define CIOT_CONFIG_ETH_GPIO_PHY_RST 5
// #define CIOT_CONFIG_ETH_GPIO_MDC 23
// #define CIOT_CONFIG_ETH_GPIO_MDIO 18

// #define CIOT_CONFIG_WIFI_AP_SSID_MASK "CIOT BOARD %s"
// #define CIOT_CONFIG_WIFI_AP_PASS "administrator"
// #define CIOT_CONFIG_WIFI_AP_AUTH WIFI_AUTH_WPA_WPA2_PSK
// #define CIOT_CONFIG_WIFI_AP_MAX_CONN 1

// #define CIOT_CONFIG_WIFI_STA_SSID "CABO CANAVERAL"
// #define CIOT_CONFIG_WIFI_STA_PASS "16192020"

// #define CIOT_CONFIG_NTP_OP_MODE 0
// #define CIOT_CONFIG_NTP_SYNC_MODE 0
// #define CIOT_CONFIG_NTP_SYNC_INTERVAL (3600 * 1000)
// #define CIOT_CONFIG_NTP_TZ "<-03>3"
// #define CIOT_CONFIG_NTP_SERVERS_COUNT 3
// #define CIOT_CONFIG_NTP_SERVER1 "pool.ntp.org"
// #define CIOT_CONFIG_NTP_SERVER2 "time.google.com"
// #define CIOT_CONFIG_NTP_SERVER3 "gps.ntp.br"

// #define CIOT_CONFIG_OTA_TASK_STACK_SIZE 8192
// #define CIOT_CONFIG_OTA_TASK_TASK_PRIORITY (tskIDLE_PRIORITY + 4)
// #define CIOT_CONFIG_OTA_TASK_CORE_ID 1

#endif //!__CIOT_CUSTOM_CONFIG__H__
108 changes: 108 additions & 0 deletions examples/win32/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* @file main.c
* @author your name (you@domain.com)
* @brief
* @version 0.1
* @date 2023-11-02
*
* @copyright Copyright (c) 2023
*
*/

#include <stdio.h>
#include <stdbool.h>

#include "mongoose.h"

#include "ciot_sys.h"
#include "ciot_uart.h"
#include "ciot_https.h"
#include "ciot_httpc.h"
#include "ciot_httpc.h"
#include "ciot_mqttc.h"

#include "ciot_custom_config.h"

static struct mg_mgr mgr;

static ciot_sys_t sys;
static ciot_uart_t uart;
static ciot_https_t https;
static ciot_httpc_t httpc;
static ciot_mqttc_t mqttc;

static ciot_err_t uart_start(void);
static ciot_err_t https_start(void);
static ciot_err_t httpc_start(void);
static ciot_err_t mqttc_start(void);

int main()
{
sys = ciot_sys_new(NULL);

ciot_sys_init();
mg_mgr_init(&mgr);

uart_start();
https_start();
httpc_start();
mqttc_start();

while (true)
{
ciot_uart_task(uart);
mg_mgr_poll(&mgr, 1000);
}

return 0;
}

static ciot_err_t uart_start(void)
{
uart = ciot_uart_new(NULL);
ciot_uart_cfg_t uart_cfg = {
.baud_rate = CIOT_CONFIG_UART_BAUD,
.num = CIOT_CONFIG_UART_PORT,
};
return ciot_uart_start(uart, &uart_cfg);
}

static ciot_err_t https_start(void)
{
https = ciot_https_new(&mgr);
ciot_https_cfg_t https_cfg = {
.address = "127.0.0.1",
.port = 8080,
.route = "/v1/ciot",
};
return ciot_https_start(https, &https_cfg);
}

static ciot_err_t httpc_start(void)
{
httpc = ciot_httpc_new(&mgr);
ciot_httpc_cfg_t httpc_cfg = {
.url = "v1/ciot",
.transport = CIOT_HTTPC_TRANSPORT_TCP,
.method = CIOT_HTTPC_METHOD_POST,
.timeout = CIOT_CONFIG_HTTPC_TIMEOUT,
};
return ciot_httpc_start(httpc, &httpc_cfg);
}

static ciot_err_t mqttc_start(void)
{
mqttc = ciot_mqttc_new(&mgr);
ciot_mqttc_cfg_t mqtt_cfg = {
.client_id = "mqtt_client_id",
.url = "mqtt://test.mosquitto.org",
.port = 1883,
.qos = 0,
.topics = {
.b2d = "CIOT/B2D",
.d2b = "CIOT/D2B",
}
};
return ciot_mqttc_start(mqttc, &mqtt_cfg);
}

0 comments on commit cc39e28

Please sign in to comment.