Skip to content

Commit

Permalink
feat: Test IOTish things
Browse files Browse the repository at this point in the history
  • Loading branch information
disq committed Nov 18, 2022
1 parent 8b2a888 commit 4751476
Show file tree
Hide file tree
Showing 10 changed files with 694 additions and 11 deletions.
44 changes: 35 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ add_compile_options(-Wall
-Wno-maybe-uninitialized
)

# Add your source files
add_executable(${NAME}
main.cpp ledcontrol.cpp ledcontrol.h util.h config.h encoder.cpp encoder.h
)
if ((PICO_CYW43_SUPPORTED) AND (TARGET pico_cyw43_arch))
add_executable(${NAME}
main.cpp ledcontrol.cpp ledcontrol.h util.h config.h encoder.cpp encoder.h iot.cpp iot.h config_iot.h mbedtls_util.c
)
else()
add_executable(${NAME}
main.cpp ledcontrol.cpp ledcontrol.h util.h config.h encoder.cpp encoder.h
)
endif()

# Include required libraries
# This assumes `pimoroni-pico` is stored alongside your project
Expand All @@ -49,12 +54,33 @@ target_link_libraries(${NAME}
pico_bootsel_via_double_reset
)

if (PICO_CYW43_SUPPORTED) # set by BOARD=pico-w
if (TARGET pico_cyw43_arch)
target_link_libraries(${NAME}
pico_cyw43_arch_none # we need Wifi to access the GPIO, but we don't need anything else
)
if ((PICO_CYW43_SUPPORTED) AND (TARGET pico_cyw43_arch)) # set by BOARD=pico-w
set(WIFI_SSID "${WIFI_SSID}" CACHE INTERNAL "WiFi SSID")
set(WIFI_PASSWORD "${WIFI_PASSWORD}" CACHE INTERNAL "WiFi password")

if ("${WIFI_SSID}" STREQUAL "")
message(FATAL_ERROR "Skipping build as WIFI_SSID is not defined")
elseif ("${WIFI_PASSWORD}" STREQUAL "")
message(FATAL_ERROR "Skipping build as WIFI_PASSWORD is not defined")
endif()

target_compile_definitions(${NAME} PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
)

target_include_directories(${NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts
)

target_link_libraries(${NAME}
# pico_cyw43_arch_lwip_poll
pico_cyw43_arch_lwip_threadsafe_background
pico_lwip_mbedtls
pico_mbedtls
pico_lwip_mqtt
)
endif()

pico_enable_stdio_usb(${NAME} 1)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ And the Pico SDK:
```
git clone https://github.com/raspberrypi/pico-sdk
cd pico-sdk
git checkout develop # Switch to develop branch
git submodule update --init
export PICO_SDK_PATH=`pwd`
cd ../
Expand Down
61 changes: 61 additions & 0 deletions config_iot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef CONFIG_IOT_H
#define CONFIG_IOT_H

// Set this if you want to connect to MQTT securely
#define MQTT_TLS

// MQTT server host name or ip address
#define MQTT_SERVER_HOST "test.mosquitto.org"

// MQTT ports
#ifdef MQTT_TLS
#define MQTT_SERVER_PORT 8883
#else
#define MQTT_SERVER_PORT 1883
#endif

// Enable this if you don't want certificate verification but still want to connect with TLS
//#define MQTT_TLS_INSECURE

//#define MQTT_SERVER_HOST "91.121.93.94"
// add contents of https://test.mosquitto.org/ssl/mosquitto.org.crt here
#define MQTT_TLS_CERT "-----BEGIN CERTIFICATE-----\n" \
"MIIEAzCCAuugAwIBAgIUBY1hlCGvdj4NhBXkZ/uLUZNILAwwDQYJKoZIhvcNAQEL\n" \
"BQAwgZAxCzAJBgNVBAYTAkdCMRcwFQYDVQQIDA5Vbml0ZWQgS2luZ2RvbTEOMAwG\n" \
"A1UEBwwFRGVyYnkxEjAQBgNVBAoMCU1vc3F1aXR0bzELMAkGA1UECwwCQ0ExFjAU\n" \
"BgNVBAMMDW1vc3F1aXR0by5vcmcxHzAdBgkqhkiG9w0BCQEWEHJvZ2VyQGF0Y2hv\n" \
"by5vcmcwHhcNMjAwNjA5MTEwNjM5WhcNMzAwNjA3MTEwNjM5WjCBkDELMAkGA1UE\n" \
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/xRlEm+tvKGGmfFcN0piqVl8OrSPBgIlb+1IKJE\n" \
"m/XriWr/Cq4h/JfB7NTsezVslgkBaoU=\n" \
"-----END CERTIFICATE-----\n";

// Enable and configure these if you want client side certificates
/*
#define MQTT_TLS_KEY \
"-----BEGIN RSA PRIVATE KEY-----\n" \
"-----END RSA PRIVATE KEY-----";
#define MQTT_TLS_CA \
"-----BEGIN CERTIFICATE-----\n" \
"-----END CERTIFICATE-----";
*/

#define MQTT_CLIENT_ID "PicoW Ledcontrol"
//#define MQTT_CLIENT_USER ""
//#define MQTT_CLIENT_PASS ""

#endif
Loading

0 comments on commit 4751476

Please sign in to comment.