Compare commits

..

No commits in common. "c2e6c645b3b678752b55a8b8f09f29ace26e309d" and "f485d0b2f727641776d650fe4a6591f8e1566f9f" have entirely different histories.

6 changed files with 10 additions and 90 deletions

3
.gitmodules vendored
View file

@ -2,6 +2,3 @@
path = components/esp_netif_lora path = components/esp_netif_lora
url = https://git.oit.cloud/morgan/esp_netif_lora.git url = https://git.oit.cloud/morgan/esp_netif_lora.git
branch = development branch = development
[submodule "esp-idf"]
path = esp-idf
url = https://github.com/espressif/esp-idf.git

View file

@ -5,4 +5,4 @@ cmake_minimum_required(VERSION 3.16)
add_compile_options(-fdiagnostics-color=always) add_compile_options(-fdiagnostics-color=always)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(lora_netif_example) project(coatt)

@ -1 +1 @@
Subproject commit a893586025d4f8591de124b42a9ba529fd397a31 Subproject commit 990f338826b50c3bca9953dcea7411ac841cd1c1

@ -1 +0,0 @@
Subproject commit 3b8741b172dc951e18509698dee938304bcf1523

View file

@ -1,5 +1,2 @@
idf_component_register( idf_component_register(SRCS "main.c"
INCLUDE_DIRS "." INCLUDE_DIRS ".")
SRCS "main.c"
REQUIRES esp_netif_lora
)

View file

@ -1,19 +1,14 @@
#include "esp_random.h" #include <string.h>
#include "esp_log.h" #include "esp_log.h"
#include "esp_mac.h" #include "esp_mac.h"
#include "socket.h" #include "esp_wifi.h"
#include "nvs_flash.h"
#include "esp_netif_lora.h" #include "esp_netif_lora.h"
#define TAG "netif"
void app_main() { void app_main() {
static esp_netif_lora_config_t config; esp_netif_lora_config_t config;
config.netif = NULL;
config.lora = NULL;
ESP_LOGI(TAG, "config.lora: %p", (void*)config.lora);
esp_efuse_mac_get_default((uint8_t*)&config.mac); esp_efuse_mac_get_default((uint8_t*)&config.mac);
@ -21,74 +16,6 @@ void app_main() {
esp_netif_set_ip4_addr(&config.ip_info.gw, 10, 10 , 0, 1); esp_netif_set_ip4_addr(&config.ip_info.gw, 10, 10 , 0, 1);
esp_netif_set_ip4_addr(&config.ip_info.netmask, 255, 255 , 255, 0); esp_netif_set_ip4_addr(&config.ip_info.netmask, 255, 255 , 255, 0);
//esp_log_level_set("spi_master", ESP_LOG_DEBUG); esp_log_level_set("LoRa32", ESP_LOG_INFO);
//esp_log_level_set("LoRa32", ESP_LOG_DEBUG);
esp_netif_lora_init(&config); esp_netif_lora_init(&config);
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
struct sockaddr_in local_addr;
local_addr.sin_family = AF_INET;
//local_addr.sin_addr.s_addr = config.ip_info.ip.addr;
local_addr.sin_addr.s_addr = INADDR_ANY;
local_addr.sin_port = htons(666);
//ESP_ERROR_CHECK(ret);
struct timeval timeout;
timeout.tv_sec = esp_random() % 4 + 1;
timeout.tv_usec = 0;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, NULL, 0);
ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr("224.0.1.187");
mreq.imr_interface.s_addr = config.ip_info.ip.addr;
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&mreq, sizeof(mreq));
// TODO double check this is actually part of accepting multicast
// or if it was just binding to INADDR_ANY
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (void*)1, 1);
int ret = bind(sock, (struct sockaddr *)&local_addr, sizeof(local_addr));
ESP_LOGI(TAG, "looping");
uint8_t buf[200];
uint8_t client_addr_len;
ssize_t recieved;
ssize_t sent;
buf[0] = 0x06;
buf[1] = 0x06;
buf[2] = 0x06;
struct sockaddr_in broadcast;
broadcast.sin_family = AF_INET;
broadcast.sin_addr.s_addr = inet_addr("224.0.1.187");
broadcast.sin_port = htons(666);
while(1) {
recieved = recvfrom(sock, &buf, 255, 0, (struct sockaddr *)&local_addr, (socklen_t *)&client_addr_len);
if((int)recieved == -1) {
sent = sendto(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&broadcast, sizeof(broadcast));
if(sent == -1) {
ESP_LOGI(TAG, "sendto errno: %d", errno);
}
} else {
ESP_LOGI(TAG, "buf[0] = %d", buf[0]);
buf[0]++;
sent = sendto(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&broadcast, sizeof(broadcast));
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
} }