Compare commits
4 commits
stable
...
eleon/dev/
Author | SHA1 | Date | |
---|---|---|---|
224fc57582 | |||
010279c191 | |||
46214c86ff | |||
e6afaf6451 |
9 changed files with 374 additions and 8 deletions
5
Makefile
5
Makefile
|
@ -19,6 +19,11 @@ clean:
|
|||
+@make -C firmware clean
|
||||
+@make -C pcb clean
|
||||
|
||||
flash_docker:
|
||||
sh -c "docker build -t fiatlux_firmware_env docker/firmware"
|
||||
sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware --device=/dev/ttyUSB0 fiatlux_firmware_env make -C firmware flash"
|
||||
|
||||
|
||||
firmware_docker:
|
||||
sh -c "docker build -t fiatlux_firmware_env docker/firmware"
|
||||
sh -c "docker run --volume "$$(pwd)"/firmware:/app/firmware fiatlux_firmware_env make -C firmware all"
|
||||
|
|
|
@ -8,6 +8,6 @@ RUN cd app/modules/sdk; export CT_EXPERIMENTAL=y; export CT_ALLOW_BUILD_AS_ROOT=
|
|||
USER 0
|
||||
RUN apt remove --purge -y python2 && apt autoremove --purge -y && apt install -y python3 python3-serial perl
|
||||
RUN apt install -y --reinstall python-is-python3
|
||||
USER 1000
|
||||
USER 0
|
||||
WORKDIR /app
|
||||
ENV PATH=/app/modules/sdk/xtensa-lx106-elf/bin:$PATH
|
|
@ -2,7 +2,8 @@ PROGRAM=fiatlux
|
|||
|
||||
EXTRA_CFLAGS=-O3 -Ifsdata
|
||||
|
||||
EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support
|
||||
|
||||
EXTRA_COMPONENTS=extras/i2s_dma extras/ws2812_i2s extras/dhcpserver extras/rboot-ota extras/mbedtls extras/httpd extras/sntp extras/cpp_support extras/paho_mqtt_c
|
||||
|
||||
LIBS = hal m
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
void user_init(void)
|
||||
{
|
||||
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version: %s\n", sdk_system_get_sdk_version());
|
||||
|
||||
|
@ -22,6 +23,8 @@ void user_init(void)
|
|||
|
||||
wifi_available_semaphore = xSemaphoreCreateBinary();
|
||||
|
||||
xTaskCreate(mqtt_task, "mqtt_task", 1024, NULL, 1, NULL);
|
||||
|
||||
xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL);
|
||||
|
||||
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<label for="bmenub" class="burger pseudo button">☰</label>
|
||||
<div class="menu">
|
||||
<a href="/#" class="button icon-picture">Dashboard</a>
|
||||
<a href="/#wifi" class="button icon-puzzle">Wifi Settings</a>
|
||||
<a href="/#ota" class="button icon-picture">System</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -58,6 +59,87 @@
|
|||
</article>
|
||||
|
||||
</section>
|
||||
<section id="wifi">
|
||||
<h2>Wifi Settings</h2>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>AP Mode</h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>Enable</label>
|
||||
<span><input id="ap_toggle" type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SSID</label>
|
||||
<span><input id="ap_ssid" type="text" placeholder="SSID"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Password</label>
|
||||
<span><input id="ap_pw" type="password" placeholder="Password"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>AP IP</span>
|
||||
<span><span class="postfill_apip">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>AP MAC</span>
|
||||
<span><span class="postfill_apmac">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input onclick="ap_update();" type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
<article class="card">
|
||||
<header>
|
||||
<h3>Station Mode <span class="label success">current connection</span></h3>
|
||||
</header>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<label>Eanable</label>
|
||||
<span><input id="sta_toggle" type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>SSID</label>
|
||||
<span><input id="sta_ssid" type="text" placeholder="SSID"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Password</label>
|
||||
<span><input id="sta_pw" type="password" placeholder="Password"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Use DHCP</label>
|
||||
<span><input id="sta_shcp" type="checkbox" class="plain"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Static IP</label>
|
||||
<span><input id="sta_static_ip" type="text" placeholder="192.168.1.2"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Static Netmask</label>
|
||||
<span><input id="sta_static_netmask" type="text" placeholder="255.255.255.0"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label>Static Gateway</label>
|
||||
<span><input id="sta_static_gateway" type="text" placeholder="192.168.1.1"/></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>Sation IP</span>
|
||||
<span><span class="postfill_staip">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span>Station MAC</span>
|
||||
<span><span class="postfill_stamac">N/A</span></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span><input type="reset" class="button"/></span>
|
||||
<span><input onclick="sta_update();" type="submit" value="Save"></span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
<section id="dashboard">
|
||||
<h2>Status</h2>
|
||||
<div class="flex">
|
||||
|
@ -190,6 +272,18 @@
|
|||
return pos;
|
||||
};
|
||||
|
||||
DataView.prototype.setInt8Vec = function (pos, vec) {
|
||||
for (var i = 0; i < vec.length; i++) {
|
||||
this.setInt8(pos++, vec[i]);
|
||||
}
|
||||
return pos;
|
||||
};
|
||||
|
||||
function colorStringToVec(hex) {
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result ? [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)] : null;
|
||||
}
|
||||
|
||||
var ws;
|
||||
var retries;
|
||||
var series = new TimeSeries();
|
||||
|
@ -394,6 +488,55 @@
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
var sta_toggle = document.getElementById("sta_toggle");
|
||||
var sta_ssid = document.getElementById("sta_ssid");
|
||||
var sta_pw = document.getElementById("sta_pw");
|
||||
|
||||
function sta_update() {
|
||||
var en = sta_toggle.checked;
|
||||
|
||||
const ssid = sta_ssid.value;
|
||||
const password = sta_pw.value;
|
||||
|
||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4);
|
||||
const view1 = new DataView(buffer);
|
||||
var tx_len = 0;
|
||||
view1.setChar(tx_len++, 'S');
|
||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||
tx_len = view1.setString(tx_len, ssid);
|
||||
tx_len = view1.setString(tx_len, password);
|
||||
wsWrite(buffer);
|
||||
}
|
||||
|
||||
var ap_toggle = document.getElementById("ap_toggle");
|
||||
var ap_ssid = document.getElementById("ap_ssid");
|
||||
var ap_pw = document.getElementById("ap_pw");
|
||||
|
||||
function ap_update() {
|
||||
var en = ap_toggle.checked;
|
||||
|
||||
const ssid = ap_ssid.value;
|
||||
const password = ap_pw.value;
|
||||
|
||||
const buffer = new ArrayBuffer(ssid.length + password.length + 4 + 8);
|
||||
const view1 = new DataView(buffer);
|
||||
var tx_len = 0;
|
||||
view1.setChar(tx_len++, 'A');
|
||||
view1.setChar(tx_len++, (en ? "E" : "D"));
|
||||
tx_len = view1.setString(tx_len, ssid);
|
||||
tx_len = view1.setString(tx_len, password);
|
||||
tx_len = view1.setInt8Vec(tx_len, [192, 168, 111, 1]);
|
||||
tx_len = view1.setInt8Vec(tx_len, [255, 255, 255, 0]);
|
||||
wsWrite(buffer);
|
||||
}
|
||||
|
||||
function update_progress(progressBar, progress) {
|
||||
var iP = Math.floor(progress);
|
||||
var dBar = document.getElementById("progress_bar_" + progressBar);
|
||||
dBar.innerText = iP + "%";
|
||||
dBar.style.width = progress + "%";
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,3 +3,158 @@
|
|||
//
|
||||
|
||||
#include "mqtt.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <espressif/user_interface.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include <paho_mqtt_c/MQTTESP8266.h>
|
||||
#include <paho_mqtt_c/MQTTClient.h>
|
||||
|
||||
}
|
||||
|
||||
#include <semphr.h>
|
||||
|
||||
|
||||
/* You can use http://test.mosquitto.org/ to test mqtt_client instead
|
||||
* of setting up your own MQTT server */
|
||||
#define MQTT_HOST ("172.16.0.42")
|
||||
#define MQTT_PORT 1883
|
||||
|
||||
#define MQTT_USER NULL
|
||||
#define MQTT_PASS NULL
|
||||
|
||||
QueueHandle_t publish_queue;
|
||||
#define PUB_MSG_LEN 16
|
||||
|
||||
extern "C" void beat_task(void *pvParameters) {
|
||||
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||
char msg[PUB_MSG_LEN];
|
||||
int count = 0;
|
||||
|
||||
while (1) {
|
||||
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_PERIOD_MS);
|
||||
printf("beat\r\n");
|
||||
snprintf(msg, PUB_MSG_LEN, "Beat %d\r\n", count++);
|
||||
if(xQueueSend(publish_queue, (void *) msg, 0) == pdFALSE) {
|
||||
printf("Publish queue overflow.\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void topic_received(mqtt_message_data_t *md) {
|
||||
int i;
|
||||
mqtt_message_t *message = md->message;
|
||||
printf("Received: ");
|
||||
for (i = 0; i < md->topic->lenstring.len; ++i)
|
||||
printf("%c", md->topic->lenstring.data[i]);
|
||||
|
||||
printf(" = ");
|
||||
for (i = 0; i < (int) message->payloadlen; ++i)
|
||||
printf("%c", ((char *) (message->payload))[i]);
|
||||
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
static const char *get_my_id(void) {
|
||||
// Use MAC address for Station as unique ID
|
||||
static char my_id[13];
|
||||
static bool my_id_done = false;
|
||||
int8_t i;
|
||||
uint8_t x;
|
||||
if(my_id_done)
|
||||
return my_id;
|
||||
if(!sdk_wifi_get_macaddr(STATION_IF, (uint8_t *) my_id))
|
||||
return NULL;
|
||||
for (i = 5; i >= 0; --i) {
|
||||
x = my_id[i] & 0x0F;
|
||||
if(x > 9) x += 7;
|
||||
my_id[i * 2 + 1] = x + '0';
|
||||
x = my_id[i] >> 4;
|
||||
if(x > 9) x += 7;
|
||||
my_id[i * 2] = x + '0';
|
||||
}
|
||||
my_id[12] = '\0';
|
||||
my_id_done = true;
|
||||
return my_id;
|
||||
}
|
||||
|
||||
extern "C" void mqtt_task(void *pvParameters) {
|
||||
int ret = 0;
|
||||
struct mqtt_network network;
|
||||
mqtt_client_t client = mqtt_client_default;
|
||||
char mqtt_client_id[20];
|
||||
uint8_t mqtt_buf[100];
|
||||
uint8_t mqtt_readbuf[100];
|
||||
mqtt_packet_connect_data_t data = mqtt_packet_connect_data_initializer;
|
||||
|
||||
mqtt_network_new(&network);
|
||||
memset(mqtt_client_id, 0, sizeof(mqtt_client_id));
|
||||
strcpy(mqtt_client_id, "ESP-");
|
||||
strcat(mqtt_client_id, get_my_id());
|
||||
|
||||
while (1) {
|
||||
printf("%s: started\n\r", __func__);
|
||||
printf("%s: (Re)connecting to MQTT server %s ... ", __func__,
|
||||
MQTT_HOST);
|
||||
ret = mqtt_network_connect(&network, MQTT_HOST, MQTT_PORT);
|
||||
if(ret) {
|
||||
printf("error: %d\n\r", ret);
|
||||
taskYIELD();
|
||||
continue;
|
||||
}
|
||||
printf("done\n\r");
|
||||
mqtt_client_new(&client, &network, 5000, mqtt_buf, 100,
|
||||
mqtt_readbuf, 100);
|
||||
|
||||
data.willFlag = 0;
|
||||
data.MQTTVersion = 3;
|
||||
data.clientID.cstring = mqtt_client_id;
|
||||
data.username.cstring = MQTT_USER;
|
||||
data.password.cstring = MQTT_PASS;
|
||||
data.keepAliveInterval = 10;
|
||||
data.cleansession = 0;
|
||||
printf("Send MQTT connect ... ");
|
||||
ret = mqtt_connect(&client, &data);
|
||||
if(ret) {
|
||||
printf("error: %d\n\r", ret);
|
||||
mqtt_network_disconnect(&network);
|
||||
taskYIELD();
|
||||
continue;
|
||||
}
|
||||
printf("done\r\n");
|
||||
mqtt_subscribe(&client, "/esptopic", MQTT_QOS1, topic_received);
|
||||
xQueueReset(publish_queue);
|
||||
|
||||
while (1) {
|
||||
|
||||
char msg[PUB_MSG_LEN - 1] = "\0";
|
||||
while (xQueueReceive(publish_queue, (void *) msg, 0) ==
|
||||
pdTRUE) {
|
||||
printf("got message to publish\r\n");
|
||||
mqtt_message_t message;
|
||||
message.payload = msg;
|
||||
message.payloadlen = PUB_MSG_LEN;
|
||||
message.dup = 0;
|
||||
message.qos = MQTT_QOS1;
|
||||
message.retained = 0;
|
||||
ret = mqtt_publish(&client, "/beat", &message);
|
||||
if(ret != MQTT_SUCCESS) {
|
||||
printf("error while publishing message: %d\n", ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret = mqtt_yield(&client, 1000);
|
||||
if(ret == MQTT_DISCONNECTED)
|
||||
break;
|
||||
}
|
||||
printf("Connection dropped, request restart\n\r");
|
||||
mqtt_network_disconnect(&network);
|
||||
taskYIELD();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void mqtt_task(void *pvParameters);
|
||||
void beat_task(void *pvParameters);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -184,6 +184,18 @@ void websocket_task(void *pvParameter) {
|
|||
|
||||
}
|
||||
|
||||
vTaskDelayMs(250);
|
||||
{
|
||||
uint8_t response[3];
|
||||
uint16_t val;
|
||||
val = sdk_system_adc_read();
|
||||
response[2] = (uint8_t) val;
|
||||
response[1] = val >> 8;
|
||||
response[0] = 'V';
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, response, 3, WS_BIN_MODE);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
}
|
||||
vTaskDelayMs(500);
|
||||
}
|
||||
|
||||
|
@ -221,7 +233,18 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
|
||||
bool togl = 0;
|
||||
|
||||
int8_t en = 0;
|
||||
/*uint8_t ap_disable_if_sta = 0;
|
||||
uint8_t ssid_hidden = 0;
|
||||
uint8_t dns_enable = 0;
|
||||
uint8_t mdns_enable = 0;*/
|
||||
|
||||
switch (data[0]) {
|
||||
case 'V': // ADC
|
||||
/* This should be done on a separate thread in 'real' applications */
|
||||
val = sdk_system_adc_read();
|
||||
cmd = 'V';
|
||||
break;
|
||||
case 'R': // Restart
|
||||
cmd = 'R';
|
||||
break;
|
||||
|
@ -258,6 +281,39 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
}
|
||||
cmd = 'C';
|
||||
break;
|
||||
case 'S': {
|
||||
if(data[1] == 'E')
|
||||
en = 1;
|
||||
char *ssid = &data[2];
|
||||
size_t ssid_len = strlen(ssid);
|
||||
char *password = &data[3 + ssid_len];
|
||||
size_t password_len = strlen(password);
|
||||
(void) password_len;
|
||||
|
||||
sysparam_set_int8("wifi_sta_enable", en);
|
||||
sysparam_set_string("wifi_sta_ssid", ssid);
|
||||
sysparam_set_string("wifi_sta_password", password);
|
||||
}
|
||||
cmd = 'S';
|
||||
break;
|
||||
case 'A': {
|
||||
if(data[1] == 'E')
|
||||
en = 1;
|
||||
char *ssid = &data[2];
|
||||
size_t ssid_len = strlen(ssid);
|
||||
char *password = &data[3 + ssid_len];
|
||||
size_t password_len = strlen(password);
|
||||
(void) password_len;
|
||||
|
||||
sysparam_set_int8("wifi_ap_enable", en);
|
||||
sysparam_set_string("wifi_ap_ssid", ssid);
|
||||
sysparam_set_string("wifi_ap_password", password);
|
||||
|
||||
//sysparam_set_int8("wifi_ap_dns", dns_enable);
|
||||
//sysparam_set_int8("wifi_ap_mdns", mdns_enable);
|
||||
}
|
||||
cmd = 'A';
|
||||
break;
|
||||
default:
|
||||
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
||||
printf("Unknown command %c\n", data[0]);
|
||||
|
|
|
@ -210,7 +210,7 @@ extern "C" void wifi_task(void *pvParameters) {
|
|||
|
||||
if(wifi_sta_enable) {
|
||||
printf("try STA Mode: %s %s\n", wifi_sta_ssid, wifi_sta_password);
|
||||
sdk_station_config config;
|
||||
sdk_station_config config{};
|
||||
strcpy((char *) config.ssid, wifi_sta_ssid);
|
||||
strcpy((char *) config.password, wifi_sta_password);
|
||||
config.bssid_set = 0;
|
||||
|
@ -230,7 +230,7 @@ extern "C" void wifi_task(void *pvParameters) {
|
|||
wifi_sta_netmask && strlen(wifi_sta_netmask) > 4 &&
|
||||
wifi_sta_gateway && strlen(wifi_sta_gateway) > 4) {
|
||||
sdk_wifi_station_dhcpc_stop();
|
||||
ip_info info;
|
||||
ip_info info{};
|
||||
memset(&info, 0x0, sizeof(info));
|
||||
info.ip.addr = ipaddr_addr(wifi_sta_ip_addr);
|
||||
info.netmask.addr = ipaddr_addr(wifi_sta_netmask);
|
||||
|
@ -305,13 +305,13 @@ extern "C" void wifi_task(void *pvParameters) {
|
|||
}
|
||||
|
||||
if(strlen(wifi_ap_ip_addr) >= 7 && strlen(wifi_ap_netmask) >= 7) {
|
||||
ip_info ap_ip;
|
||||
ip_info ap_ip{};
|
||||
ap_ip.ip.addr = ipaddr_addr(wifi_ap_ip_addr);
|
||||
ap_ip.netmask.addr = ipaddr_addr(wifi_ap_netmask);
|
||||
IP4_ADDR(&ap_ip.gw, 0, 0, 0, 0);
|
||||
sdk_wifi_set_ip_info(1, &ap_ip);
|
||||
|
||||
sdk_softap_config ap_config;
|
||||
sdk_softap_config ap_config{};
|
||||
strcpy((char *) ap_config.ssid, wifi_ap_ssid);
|
||||
ap_config.ssid_len = strlen(wifi_ap_ssid);
|
||||
strcpy((char *) ap_config.password, wifi_ap_password);
|
||||
|
|
Loading…
Reference in a new issue