-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mosq): Add example with serverless brokers
- Loading branch information
1 parent
8855c6d
commit 84143de
Showing
10 changed files
with
512 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
components/mosquitto/examples/serverless_mqtt/components/libjuice/port/juice_random.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# 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.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(serverless_mqtt) |
66 changes: 66 additions & 0 deletions
66
components/mosquitto/examples/serverless_mqtt/components/libjuice/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
set(LIBJUICE_VERSION "73785387eafe15c02b6a210edb10f722474e8e14") | ||
set(LIBJUICE_URL "https://github.com/paullouisageneau/libjuice/archive/${LIBJUICE_VERSION}.zip") | ||
|
||
# Directory to store the downloaded library | ||
set(libjuice_dir ${CMAKE_BINARY_DIR}/libjuice/libjuice-${LIBJUICE_VERSION}) | ||
|
||
# Fetch the library | ||
if(NOT EXISTS ${libjuice_dir}) | ||
message(STATUS "Downloading libjuice ${LIBJUICE_VERSION}...") | ||
file(DOWNLOAD ${LIBJUICE_URL} ${CMAKE_BINARY_DIR}/libjuice.zip SHOW_PROGRESS) | ||
execute_process(COMMAND unzip -o ${CMAKE_BINARY_DIR}/libjuice.zip -d ${CMAKE_BINARY_DIR}/libjuice | ||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
endif() | ||
|
||
#set(libjuice_dir ${CMAKE_BINARY_DIR}/libjuice/libjuice-1.5.7) | ||
## Path to the downloaded libjuice source | ||
##ExternalProject_Get_Property(libjuice_project libjuice_dir) | ||
#set(libjuice_dir ${CMAKE_BINARY_DIR}/libjuice/libjuice-1.5.7/) | ||
|
||
set(JUICE_SOURCES ${libjuice_dir}/src/addr.c | ||
${libjuice_dir}/src/agent.c | ||
${libjuice_dir}/src/base64.c | ||
${libjuice_dir}/src/conn.c | ||
${libjuice_dir}/src/conn_mux.c | ||
${libjuice_dir}/src/conn_poll.c | ||
${libjuice_dir}/src/conn_thread.c | ||
${libjuice_dir}/src/const_time.c | ||
${libjuice_dir}/src/crc32.c | ||
${libjuice_dir}/src/hash.c | ||
${libjuice_dir}/src/ice.c | ||
${libjuice_dir}/src/juice.c | ||
${libjuice_dir}/src/log.c | ||
${libjuice_dir}/src/server.c | ||
${libjuice_dir}/src/stun.c | ||
${libjuice_dir}/src/timestamp.c | ||
${libjuice_dir}/src/turn.c | ||
${libjuice_dir}/src/udp.c | ||
# Use hmac from mbedtls and random numbers from esp_random: | ||
# ${libjuice_dir}/src/hmac.c | ||
# ${libjuice_dir}/src/random.c | ||
) | ||
|
||
message(INFO ${JUICE_SOURCES}) | ||
idf_component_register(SRCS port/juice_random.c | ||
${JUICE_SOURCES} | ||
INCLUDE_DIRS "include" "${libjuice_dir}/include" "${libjuice_dir}/include/juice" | ||
REQUIRES esp_netif | ||
PRIV_REQUIRES sock_utils) | ||
|
||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") | ||
|
||
#add_custom_target(target1 DEPENDS file1) | ||
# Define a custom target to download the GitHub repository | ||
#https://github.com/github/codeql/archive/refs/tags/v1.5.7.zip | ||
#add_custom_command( | ||
# OUTPUT ${CMAKE_BINARY_DIR}/libjuice.timestamp | ||
# COMMAND wget https://github.com/paullouisageneau/libjuice/archive/refs/tags/v1.5.7.zip -O ${CMAKE_BINARY_DIR}/libjuice.zip | ||
# COMMAND unzip -o ${CMAKE_BINARY_DIR}/libjuice.zip -d ${CMAKE_BINARY_DIR}/libjuice | ||
# COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/libjuice.timestamp | ||
# COMMENT "Downloading and extracting the repository" | ||
# VERBATIM | ||
#) | ||
# | ||
#add_custom_target(download_repo ALL DEPENDS ${CMAKE_BINARY_DIR}/libjuice.timestamp) | ||
# | ||
#add_dependencies(${COMPONENT_LIB} download_repo) |
9 changes: 9 additions & 0 deletions
9
components/mosquitto/examples/serverless_mqtt/components/libjuice/include/ifaddrs.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#pragma once | ||
//#error hi | ||
#define udp_sendto juice_udp_sendto | ||
#include_next "ifaddrs.h" |
40 changes: 40 additions & 0 deletions
40
components/mosquitto/examples/serverless_mqtt/components/libjuice/port/juice_random.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2020 Paul-Louis Ageneau | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
#include "esp_random.h" | ||
|
||
void juice_random(void *buf, size_t size) | ||
{ | ||
esp_fill_random(buf, size); | ||
} | ||
|
||
void juice_random_str64(char *buf, size_t size) | ||
{ | ||
static const char chars64[] = | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
size_t i = 0; | ||
for (i = 0; i + 1 < size; ++i) { | ||
uint8_t byte = 0; | ||
juice_random(&byte, 1); | ||
buf[i] = chars64[byte & 0x3F]; | ||
} | ||
buf[i] = '\0'; | ||
} | ||
|
||
uint32_t juice_rand32(void) | ||
{ | ||
uint32_t r = 0; | ||
juice_random(&r, sizeof(r)); | ||
return r; | ||
} | ||
|
||
uint64_t juice_rand64(void) | ||
{ | ||
uint64_t r = 0; | ||
juice_random(&r, sizeof(r)); | ||
return r; | ||
} |
12 changes: 12 additions & 0 deletions
12
components/mosquitto/examples/serverless_mqtt/main/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
idf_component_register(SRCS "serverless_mqtt.c" | ||
"wifi_connect.c" | ||
INCLUDE_DIRS "." | ||
REQUIRES libjuice nvs_flash mqtt json esp_wifi) | ||
|
||
if(PEER1) | ||
target_compile_definitions(${COMPONENT_LIB} PRIVATE "PEER1") | ||
elseif(PEER2) | ||
target_compile_definitions(${COMPONENT_LIB} PRIVATE "PEER2") | ||
else() | ||
message(FATAL_ERROR "Please define either PEER1 or PEER2") | ||
endif() |
5 changes: 5 additions & 0 deletions
5
components/mosquitto/examples/serverless_mqtt/main/idf_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## IDF Component Manager Manifest File | ||
dependencies: | ||
espressif/mosquitto: | ||
override_path: ../../.. | ||
espressif/sock_utils: "*" |
Oops, something went wrong.