Browse Source

Updated README file; added license headers; fixed wifi issues

master
chodak166 4 years ago
parent
commit
478e351408
  1. 7
      COPYRIGHT.txt
  2. 5
      LICENSE
  3. 20
      LICENSE.txt
  4. 178
      README.md
  5. 0
      case/CaseBody.scad
  6. 0
      case/CaseBodyExtended.scad
  7. 0
      case/CaseRoof.scad
  8. 0
      case/Cover.scad
  9. 0
      case/LedHook.scad
  10. 0
      case/RfBoard.scad
  11. 0
      case/SnapFit.scad
  12. 0
      case/TargetPcb.scad
  13. 0
      case/config.scad
  14. 0
      case/mqtrigger.stl
  15. 4
      components/firmware/include/nx/firmware/Buttons.h
  16. 4
      components/firmware/include/nx/firmware/GpioTrigger.h
  17. 4
      components/firmware/include/nx/firmware/HwConfig.h
  18. 4
      components/firmware/include/nx/firmware/MqTriggerHttpServer.h
  19. 4
      components/firmware/include/nx/firmware/MqttClient.h
  20. 4
      components/firmware/include/nx/firmware/Restarter.h
  21. 4
      components/firmware/include/nx/firmware/SntpClient.h
  22. 4
      components/firmware/include/nx/firmware/StatusIndicator.h
  23. 4
      components/firmware/include/nx/firmware/Storage.h
  24. 4
      components/firmware/include/nx/firmware/Wifi.h
  25. 4
      components/firmware/src/Buttons.c
  26. 4
      components/firmware/src/GpioTrigger.c
  27. 4
      components/firmware/src/HttpHelpers.c
  28. 4
      components/firmware/src/HttpHelpers.h
  29. 4
      components/firmware/src/MqTriggerHttpServer.c
  30. 4
      components/firmware/src/MqttClient.c
  31. 4
      components/firmware/src/Restarter.c
  32. 4
      components/firmware/src/SntpClient.c
  33. 10
      components/firmware/src/StatusIndicator.c
  34. 4
      components/firmware/src/Storage.c
  35. 10
      components/firmware/src/Wifi.c
  36. 4
      components/software/include/nx/software/AppSettings.h
  37. 4
      components/software/include/nx/software/AppSettingsApi.h
  38. 4
      components/software/include/nx/software/CommandParser.h
  39. 4
      components/software/include/nx/software/SystemSettings.h
  40. 4
      components/software/include/nx/software/SystemSettingsApi.h
  41. 4
      components/software/src/AppSettings.c
  42. 14
      components/software/src/AppSettingsApi.c
  43. 4
      components/software/src/CommandParser.c
  44. 4
      components/software/src/KeyValueParser.c
  45. 4
      components/software/src/KeyValueParser.h
  46. 4
      components/software/src/SystemSettings.c
  47. 4
      components/software/src/SystemSettingsApi.c
  48. BIN
      doc/img/pinout.png
  49. 26
      doc/tme.csv
  50. 4
      main/HttpHandlers.h
  51. 4
      main/Main.c
  52. 50
      main/MqtriggerApp.c
  53. 4
      main/MqtriggerApp.h
  54. 2
      main/static/index.html
  55. 6
      main/static/index.js
  56. 2
      main/static/min/index.html
  57. 6
      main/static/min/index.js

7
COPYRIGHT.txt

@ -0,0 +1,7 @@
Espressif IoT Development Framework,
Apache License Version 2.0
https://github.com/espressif/esp-idf/blob/release/v4.2/LICENSE
Milligram CSS framework,
The MIT License (MIT)
https://github.com/milligram/milligram/blob/release/v1.5.0/license

5
LICENSE

@ -1,5 +0,0 @@
Code in this repository is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.

20
LICENSE.txt

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2020-2022 Łukasz Chodyła
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

178
README.md

@ -1,11 +1,173 @@
ESP-IDF template app
====================
# MqTrigger
This is a template application to be used with [Espressif IoT Development Framework](https://github.com/espressif/esp-idf).
1. [Overview](#overview)
1.1. [Components](#components)
1.2. [Features](#features)
2. [How it works](#how-it-works)
2.1. [Pinout](#pinout)
2.2. [Message format](#message-format)
2.3. [Testing with mosquitto](#testing-with-mosquitto)
3. [Building](#building)
3.1. [ESP IDF installation](#esp-idf-installation)
3.2. [Compilation](#compilation)
4. [Flashing](#flashing)
4.1. [Flash using idf.py](#flash-using-idfpy)
4.2. [Flash using esptool](#flash-using-esptool)
5. [Licensing](#licensing)
Please check [ESP-IDF docs](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) for getting started instructions.
*Code in this repository is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.*
## Overview
MqTrigger is a simple, multi-channel switch controller with MQTT and HTTP APIs. The project arose from the need to drive separate boards of encoded remote controllers (433 an 868MHz gate, garage, alarm system remotes) as well as general 230V relays.
### Components
- software
- double-sided printed circuit board
- 3D printed modular casing
### Features
- switch control via local network or over the Internet using a smartphone app or command line
- local WEB configuration panel
- simple REST API for triggering and configuration
- built-in MQTT client with optional encryption (TLS) and/or user authentication
- device monitoring (heartbeats)
- input voltage 4.5-22V (depends on the regulator used)
- controlled current 35V/50mA (depends on transoptors/transistors used)
- time synchronization (SNTP) and time zone configuration
- status signalling via RGB LED
- USB software update
- power saving mode
- cooperation with popular applications for Android and iOS (such as MQTT Dashboard)
- reboot scheduling
- static and dynamic IP configuration
- DNS configuration
- access point and WiFi station mode
- service mode and factory settings reset button
## How it works
This is a standard optocoupler setup driven by ESP32 uC. You can hack into between the button pins of the remote control board with its own power supply, or use the extra power port and jumpers on the MqTrigger board. Any other circuit with GPIO or high voltage relays will also work. By design, the application switches the states of the outputs temporarily, but converting an output to e.g. PWM signal should not be a problem.
### Pinout
![mqtrigger pinout](doc/img/pinout.png)
1. DC power supply (4.5-22V)
2. UC UART GND
3. uC UART TXD pin
4. uC UART RXD pin
5. input voltage pin
6. configurable pin
7. voltage pin 3.3V
8. blue LED pin
9. green LED pin
10. cathode LED
11. red LED pin
12. programming button
13. reset button
14. service button
15. emitter of trigger 3
16. collector of trigger 3
17. emitter of trigger 2
18. collector of trigger 2
19. emitter of trigger 1
20. collector of trigger 1
21. emitter of trigger 0
22. collector of trigger 0
23. GND
24. configurable pin output
### Message format
Both HTTP (POST) requests and published MQTT messages have the same format: `<command> <arg1> <arg2> ... <argN>`.
Switch state altering commands:
`trigger <n> <duration ms>` - trigger the nth switch for a given time (milliseconds);
`on <n>` - turn on the nth switch;
`off <n>` - turn off the nth switch;
Additionally, the `/app` and `/sys` URIs accept the string in the POST request as `option1=value1&optionN=valueN`. To change device settings via MQTT, use the `setapp <options string>` or `setsys <options string>` message format. To learn more about the keys and values of application and system settings, see the `components/software/src/*Api.c` files.
MQTT message examples:
`trigger 0 2000` - turn on switch 0 for 2 seconds;
`off 3` - turn off switch 3;
`setsys wstatic=0&dns=1.1.1.1` - update system settings (here: use DHCP and set DNS server address);
`setapp mqtls=0&mqhb=mqt/test/hb` - update application settings (here: do not use TLS, set the heartbeat topic)
### Testing with mosquitto
```
mosquitto_pub -t mqt/test/api -h my-mqtt-server.net -p 8883 --cafile ./ca.crt -i client_name -u testuser -P testpassword -m "trigger 0 3000"
```
### Service mode
Press the service and the reset button, then release both buttons to boot into service mode. Now there should be unprotected (no password) access point available as `mqt-<mac>` SSID. Web control panel will be available under `192.168.4.1` IP address. Next boot will exit the service mode.
### Factory reset
Press the service and the reset button, then release reset button and keep holding the service button for at least 10 seconds. Default settings will be restored and the device will boot into the service mode.
## Building
### ESP IDF installation
Clone `esp-idf` project:
```
cd ~/src
git clone --recursive --branch v4.2.2 --depth 1 https://github.com/espressif/esp-idf.git
```
Install `esp-idf`:
```
cd ~/src/esp-idf
bash ./install.sh
```
### Compilation
Setup the environment:
```
cd mqtrigger
source ~/src/esp-idf/export.sh
```
OPTIONAL: Change project settings:
```
idf.py menuconfig
```
Run `idf.py` to build the project:
```
idf.py build
```
## Flashing
Press boot + reset button before flashing.
### Flash using idf.py
If the SDK is installed and the environment is set up, then the binary can be uploaded just after the build:
```
idf.py -p /dev/ttyUSB0 flash
```
### Flash using esptool
```
esptool -p /dev/ttyUSB0 -b 460800 \
--before default_reset --after hard_reset \
--chip esp32 write_flash --flash_mode dio --flash_size detect --flash_freq 40m \
0x1000 bootloader/bootloader.bin \
0x8000 partition_table/partition-table.bin \
0x10000 mqtrigger.bin
```
## Licensing
Distributed under the MIT License.
See accompanying file LICENSE.txt for the full license.

0
pcb/case/CaseBody.scad → case/CaseBody.scad

0
pcb/case/CaseBodyExtended.scad → case/CaseBodyExtended.scad

0
pcb/case/CaseRoof.scad → case/CaseRoof.scad

0
pcb/case/Cover.scad → case/Cover.scad

0
pcb/case/LedHook.scad → case/LedHook.scad

0
pcb/case/RfBoard.scad → case/RfBoard.scad

0
pcb/case/SnapFit.scad → case/SnapFit.scad

0
pcb/case/TargetPcb.scad → case/TargetPcb.scad

0
pcb/case/config.scad → case/config.scad

0
pcb/case/mqtrigger.stl → case/mqtrigger.stl

4
components/firmware/include/nx/firmware/Buttons.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_NXBUTTONS_H_
#define COMPONENTS_FIRMWARE_NXBUTTONS_H_

4
components/firmware/include/nx/firmware/GpioTrigger.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_GPIOTRIGGER_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_GPIOTRIGGER_H_

4
components/firmware/include/nx/firmware/HwConfig.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_HWCONFIG_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_HWCONFIG_H_

4
components/firmware/include/nx/firmware/MqTriggerHttpServer.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_FIRMWARE_MQTRIGGERHTTPSERVER_H_
#define COMPONENTS_FIRMWARE_INCLUDE_FIRMWARE_MQTRIGGERHTTPSERVER_H_

4
components/firmware/include/nx/firmware/MqttClient.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_MQTTCLIENT_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_MQTTCLIENT_H_

4
components/firmware/include/nx/firmware/Restarter.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_RESTARTER_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_RESTARTER_H_

4
components/firmware/include/nx/firmware/SntpClient.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_SNTPCLIENT_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_SNTPCLIENT_H_

4
components/firmware/include/nx/firmware/StatusIndicator.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_STATUSINDICATOR_H_
#define COMPONENTS_FIRMWARE_INCLUDE_NX_FIRMWARE_STATUSINDICATOR_H_

4
components/firmware/include/nx/firmware/Storage.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_STORAGE_H_
#define COMPONENTS_FIRMWARE_STORAGE_H_

4
components/firmware/include/nx/firmware/Wifi.h

@ -2,6 +2,10 @@
#define COMPONENTS_FIRMWARE_WIFI_H
#include <stdint.h>
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include <stddef.h>
#include <stdbool.h>

4
components/firmware/src/Buttons.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/Buttons.h"
#include <esp_log.h>

4
components/firmware/src/GpioTrigger.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/GpioTrigger.h"
#include <freertos/FreeRTOS.h>

4
components/firmware/src/HttpHelpers.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "HttpHelpers.h"
#include <esp_log.h>

4
components/firmware/src/HttpHelpers.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_FIRMWARE_SRC_HTTPHELPERS_H_
#define COMPONENTS_FIRMWARE_SRC_HTTPHELPERS_H_

4
components/firmware/src/MqTriggerHttpServer.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/MqTriggerHttpServer.h"
#include "HttpHelpers.h"

4
components/firmware/src/MqttClient.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/MqttClient.h"
#include "freertos/FreeRTOS.h"

4
components/firmware/src/Restarter.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/Restarter.h"
#include "esp_log.h"

4
components/firmware/src/SntpClient.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/SntpClient.h"
#include <time.h>
#include <sys/time.h>

10
components/firmware/src/StatusIndicator.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/StatusIndicator.h"
#include "nx/firmware/HwConfig.h"
@ -79,7 +83,7 @@ static void statusCycleOkWorking()
currentStatus = prevStatus;
}
static void statusCycleBtEnabled()
static void statusCycleOkWorkingAlt()
{
GREEN_OFF;
BLUE_ON;
@ -131,7 +135,7 @@ static void printStatus()
ets_printf("OK WORKING");
break;
case STATUS_OK_ALT:
ets_printf("BT ENABLED");
ets_printf("OK WORKING ALT");
break;
case STATUS_SYSTEM_ERROR:
ets_printf("WIFI ERROR");
@ -171,7 +175,7 @@ void nxStatusIndicatorTask(void* params)
statusCycleOkWorking();
break;
case STATUS_OK_ALT:
statusCycleBtEnabled();
statusCycleOkWorkingAlt();
break;
case STATUS_SYSTEM_ERROR:
statusCycleWifiError();

4
components/firmware/src/Storage.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/Storage.h"
#include <esp_log.h>

10
components/firmware/src/Wifi.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/firmware/Wifi.h"
#include "freertos/FreeRTOS.h"
@ -129,6 +133,12 @@ static void handleApEvents(esp_event_base_t event_base, int32_t event_id, void*
{
ESP_LOGI(TAG, "WiFi AP event received; event ID: %i", event_id);
if (event_id == WIFI_EVENT_AP_START) {
ESP_LOGI(TAG, "WiFi AP started");
if (connectedCallback) {
connectedCallback();
}
}
if (event_id == WIFI_EVENT_AP_STACONNECTED) {
wifi_event_ap_staconnected_t* event = (wifi_event_ap_staconnected_t*) event_data;
ESP_LOGI(TAG, "Station "MACSTR" joined, AID=%d",

4
components/software/include/nx/software/AppSettings.h

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef NX_SOFTWARE_APPSETTINGS_H_
#define NX_SOFTWARE_APPSETTINGS_H_

4
components/software/include/nx/software/AppSettingsApi.h

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef NX_SOFTWARE_APPSETTINGSAPI_H_
#define NX_SOFTWARE_APPSETTINGSAPI_H_

4
components/software/include/nx/software/CommandParser.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_SOFTWARE_INCLUDE_NX_SOFTWARE_COMMANDPARSER_H_
#define COMPONENTS_SOFTWARE_INCLUDE_NX_SOFTWARE_COMMANDPARSER_H_

4
components/software/include/nx/software/SystemSettings.h

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef NX_SOFTWARE_NXSYSTEMSETTINGS_H_
#define NX_SOFTWARE_NXSYSTEMSETTINGS_H_

4
components/software/include/nx/software/SystemSettingsApi.h

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef NX_SOFTWARE_NXSYSTEMSETTINGSAPI_H_
#define NX_SOFTWARE_NXSYSTEMSETTINGSAPI_H_

4
components/software/src/AppSettings.c

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/software/AppSettings.h"
#include <stdio.h>
#include <string.h>

14
components/software/src/AppSettingsApi.c

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/software/AppSettingsApi.h"
#include "nx/software/AppSettings.h"
#include "KeyValueParser.h"
@ -18,6 +22,7 @@
#define API_KEY_CA_CERT "cacert"
#define API_KEY_OV_DEVNAME "ovdn"
#define API_KEY_CUSTOM_DEVNAME "cdn"
#define API_KEY_WDOG_MAX_SEC "wdogs"
#define UNUSED(x) (void)(x)
@ -63,6 +68,9 @@ static void handleKvPair(const char* key, const char* value, const void* userDat
else if (strcmp(key, API_KEY_OV_DEVNAME) == 0) {
settings->overrideDevName = atoi(value);
}
else if (strcmp(key, API_KEY_WDOG_MAX_SEC) == 0) {
settings->wdogMaxSec = atoi(value);
}
else {
fprintf(stderr, "Unknown key: %s\n", key);
}
@ -86,7 +94,8 @@ void nxApiGetAppSettings(const uint8_t* msg, size_t msgLen,
"\"%s\":%i, "
"\"%s\":\"%s\", " // mqtt user
"\"%s\":%i," // ovdn
"\"%s\":\"%s\"" // cdn
"\"%s\":\"%s\"," // cdn
"\"%s\":%i" // wdogs
"}",
API_KEY_MQTT_HOST , settings->mqttHost ,
API_KEY_MQTT_API_URI , settings->mqttApiUri ,
@ -95,7 +104,8 @@ void nxApiGetAppSettings(const uint8_t* msg, size_t msgLen,
API_KEY_MQTT_TLS , settings->mqttUseTls ,
API_KEY_MQTT_USER , settings->mqttUser ,
API_KEY_OV_DEVNAME , settings->overrideDevName ,
API_KEY_CUSTOM_DEVNAME, settings->customDevName
API_KEY_CUSTOM_DEVNAME, settings->customDevName ,
API_KEY_WDOG_MAX_SEC , settings->wdogMaxSec
);
*response = responseBuffer;
*respLen = strlen(responseBuffer);

4
components/software/src/CommandParser.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "nx/software/CommandParser.h"
#include <string.h>

4
components/software/src/KeyValueParser.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "KeyValueParser.h"
#include <stdio.h>

4
components/software/src/KeyValueParser.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef COMPONENTS_SOFTWARE_KEYVALUEPARSER_H_
#define COMPONENTS_SOFTWARE_KEYVALUEPARSER_H_

4
components/software/src/SystemSettings.c

@ -1,3 +1,7 @@
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "../include/nx/software/SystemSettings.h"
#include <stdio.h>

4
components/software/src/SystemSettingsApi.c

@ -3,6 +3,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
// Copyright (c) 2022 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "KeyValueParser.h"
#include <string.h>
#include "../include/nx/software/SystemSettings.h"

BIN
doc/img/pinout.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

26
doc/tme.csv

@ -0,0 +1,26 @@
typ elementu,nazwa,cena brutto szt.,szt.,cena brutto,link
Przetwornica 3.3v,AP1509-33SG-13,"4,85",2,"9,7",https://www.tme.eu/pl/details/ap1509-33sg-13/regulatory-napiecia-uklady-dc-dc/diodes-incorporated/
Diody Schottky'ego,STPS0530Z,"0,3",20,6,https://www.tme.eu/pl/details/stps0530z/diody-schottky-smd/stmicroelectronics/
Dławik,DJNR6045-470-S,"0,89",5,"4,45",https://www.tme.eu/pl/details/djnr6045-470-s/dlawiki-smd-mocy/ferrocore/
Kondensator ceramiczny 10uF,"
CL10A106KQ8NNNC","0,37",25,"9,25",https://www.tme.eu/pl/details/cl10a106kq8nnnc/kondensatory-mlcc-smd-0603/samsung/
Kondensator ceramiczny 4.7uF,CL31A475KAHNNNE,"0,66",10,"6,6",https://www.tme.eu/pl/details/cl31a475kahnnne/kondensatory-mlcc-smd-1206/samsung/
Kondensator tantalowy 0.1uF,T491A104M035AT,"1,61",0,0,https://www.tme.eu/pl/details/t491a104m035at/kondensatory-tantalowe-smd/kemet/
Kondensator ceramiczny 0.1uF,CC0603KRX7R8BB104,"0,086",100,"8,6",https://www.tme.eu/pl/details/cc0603krx7r8bb104/kondensatory-mlcc-smd-0603/yageo/
Mikroprzełącznik,TACTM-34N-F,"0,5",10,5,https://www.tme.eu/pl/details/tactm-34n-f/mikroprzelaczniki-tact/ninigi/
Rezystor 10k,CRGCQ0603J10K,"0,068",100,"6,8",https://www.tme.eu/pl/details/crgcq0603j10k/rezystory-smd-0603/te-connectivity/2-2176340-5/
Rezystor 100,CRG0402J100R/10,"0,034",100,"3,4",https://www.tme.eu/pl/details/crg0402j100r_10/rezystory-smd-0402/te-connectivity/1622826-3/
Rezystor 3.3k,WF06P-3K3-5%,"0,043",100,"4,3",https://www.tme.eu/pl/details/wf06p-3k3-5%25/rezystory-smd-0603/walsin/wf06p332jtl/
Transoptor 4ch,LTV-847S,"3,36",2,"6,72",https://www.tme.eu/pl/details/ltv-847s/transoptory-wyjscie-analogowe/liteon/
Transoptor 1ch,PS2561DL-1Y-F3-A/W,"1,67",5,"8,35",https://www.tme.eu/pl/details/ps2561dl-1y-f3-a_w/transoptory-wyjscie-analogowe/cel-renesas/
Listwa kołkowa,DS1021-1*6SF11-B,"0,263",20,"5,26",https://www.tme.eu/pl/details/zl201-06g/listwy-i-gniazda-kolkowe/connfly/ds1021-1-6sf11-b/
Listwa kołkowa,DS1021-1*10SF11-B,"0,49",10,"4,9",https://www.tme.eu/pl/details/zl201-10g/listwy-i-gniazda-kolkowe/connfly/ds1021-1-10sf11-b/
Zworka/jumper,JUMPER-G NINIGI,"0,23",20,"4,6",https://www.tme.eu/pl/details/jumper-g/listwy-i-gniazda-kolkowe/ninigi/
Złącze zaciskowe,DG301R-5.0-02P-12-00A(H),"1,16",5,"5,8",https://www.tme.eu/pl/details/dg301r-5.0-2p12/listwy-zaciskowe-do-druku/degson-electronics/dg301r-5-0-02p-12-00a-h/
Gniazdo DC 2.5mm,PC-GK2.5,"1,24",5,"6,2",https://www.tme.eu/pl/details/pc-gk2.5/zlacza-dc/ninigi/
Bezpiecznik 2A/32V,BSMD0603-SS2.0,"1,11",5,"5,55",https://www.tme.eu/pl/details/bsmd0603-ss2.0/bezpieczniki-smd-0603-superszybkie/eska/fuse-0603-ff-pw-2a0/
Dioda prostownicza,S1A,"0,16",25,4,https://www.tme.eu/pl/details/s1a-dio/diody-uniwersalne-smd/diotec-semiconductor/s1a/
ESP32,ESP32-WROOM-32E-N8 ESPRESSIF,"15,71",2,"31,42",https://www.tme.eu/pl/details/esp32-wroom-32e-8/moduly-iot-wifi-bluetooth/espressif/esp32-wroom-32e-n8/
Topnik w płynie,ART.AGT-042,"7,06",1,"7,06",https://www.tme.eu/pl/details/rf800_015/topniki/ag-termopasty/art-agt-042/
Grot ścięty stożek,SR-628,"15,02",1,"15,02",https://www.tme.eu/pl/details/sr-628/groty-lutownicze/sorny-roong-industrial/
,,,,"168,98",
1 typ elementu nazwa cena brutto szt. szt. cena brutto link
2 Przetwornica 3.3v AP1509-33SG-13 4,85 2 9,7 https://www.tme.eu/pl/details/ap1509-33sg-13/regulatory-napiecia-uklady-dc-dc/diodes-incorporated/
3 Diody Schottky'ego STPS0530Z 0,3 20 6 https://www.tme.eu/pl/details/stps0530z/diody-schottky-smd/stmicroelectronics/
4 Dławik DJNR6045-470-S 0,89 5 4,45 https://www.tme.eu/pl/details/djnr6045-470-s/dlawiki-smd-mocy/ferrocore/
5 Kondensator ceramiczny 10uF CL10A106KQ8NNNC 0,37 25 9,25 https://www.tme.eu/pl/details/cl10a106kq8nnnc/kondensatory-mlcc-smd-0603/samsung/
6 Kondensator ceramiczny 4.7uF CL31A475KAHNNNE 0,66 10 6,6 https://www.tme.eu/pl/details/cl31a475kahnnne/kondensatory-mlcc-smd-1206/samsung/
7 Kondensator tantalowy 0.1uF T491A104M035AT 1,61 0 0 https://www.tme.eu/pl/details/t491a104m035at/kondensatory-tantalowe-smd/kemet/
8 Kondensator ceramiczny 0.1uF CC0603KRX7R8BB104 0,086 100 8,6 https://www.tme.eu/pl/details/cc0603krx7r8bb104/kondensatory-mlcc-smd-0603/yageo/
9 Mikroprzełącznik TACTM-34N-F 0,5 10 5 https://www.tme.eu/pl/details/tactm-34n-f/mikroprzelaczniki-tact/ninigi/
10 Rezystor 10k CRGCQ0603J10K 0,068 100 6,8 https://www.tme.eu/pl/details/crgcq0603j10k/rezystory-smd-0603/te-connectivity/2-2176340-5/
11 Rezystor 100 CRG0402J100R/10 0,034 100 3,4 https://www.tme.eu/pl/details/crg0402j100r_10/rezystory-smd-0402/te-connectivity/1622826-3/
12 Rezystor 3.3k WF06P-3K3-5% 0,043 100 4,3 https://www.tme.eu/pl/details/wf06p-3k3-5%25/rezystory-smd-0603/walsin/wf06p332jtl/
13 Transoptor 4ch LTV-847S 3,36 2 6,72 https://www.tme.eu/pl/details/ltv-847s/transoptory-wyjscie-analogowe/liteon/
14 Transoptor 1ch PS2561DL-1Y-F3-A/W 1,67 5 8,35 https://www.tme.eu/pl/details/ps2561dl-1y-f3-a_w/transoptory-wyjscie-analogowe/cel-renesas/
15 Listwa kołkowa DS1021-1*6SF11-B 0,263 20 5,26 https://www.tme.eu/pl/details/zl201-06g/listwy-i-gniazda-kolkowe/connfly/ds1021-1-6sf11-b/
16 Listwa kołkowa DS1021-1*10SF11-B 0,49 10 4,9 https://www.tme.eu/pl/details/zl201-10g/listwy-i-gniazda-kolkowe/connfly/ds1021-1-10sf11-b/
17 Zworka/jumper JUMPER-G NINIGI 0,23 20 4,6 https://www.tme.eu/pl/details/jumper-g/listwy-i-gniazda-kolkowe/ninigi/
18 Złącze zaciskowe DG301R-5.0-02P-12-00A(H) 1,16 5 5,8 https://www.tme.eu/pl/details/dg301r-5.0-2p12/listwy-zaciskowe-do-druku/degson-electronics/dg301r-5-0-02p-12-00a-h/
19 Gniazdo DC 2.5mm PC-GK2.5 1,24 5 6,2 https://www.tme.eu/pl/details/pc-gk2.5/zlacza-dc/ninigi/
20 Bezpiecznik 2A/32V BSMD0603-SS2.0 1,11 5 5,55 https://www.tme.eu/pl/details/bsmd0603-ss2.0/bezpieczniki-smd-0603-superszybkie/eska/fuse-0603-ff-pw-2a0/
21 Dioda prostownicza S1A 0,16 25 4 https://www.tme.eu/pl/details/s1a-dio/diody-uniwersalne-smd/diotec-semiconductor/s1a/
22 ESP32 ESP32-WROOM-32E-N8 ESPRESSIF 15,71 2 31,42 https://www.tme.eu/pl/details/esp32-wroom-32e-8/moduly-iot-wifi-bluetooth/espressif/esp32-wroom-32e-n8/
23 Topnik w płynie ART.AGT-042 7,06 1 7,06 https://www.tme.eu/pl/details/rf800_015/topniki/ag-termopasty/art-agt-042/
24 Grot ścięty stożek SR-628 15,02 1 15,02 https://www.tme.eu/pl/details/sr-628/groty-lutownicze/sorny-roong-industrial/
25 168,98

4
main/HttpHandlers.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef MAIN_HTTPHANDLERS_H_
#define MAIN_HTTPHANDLERS_H_

4
main/Main.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "MqtriggerApp.h"
void app_main(void)

50
main/MqtriggerApp.c

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#include "MqtriggerApp.h"
#include "HttpHandlers.h"
@ -31,7 +35,7 @@
#define BUTTON_SERVICE_GPIO_NUM 15
#define BUTTON_SERVICE_ID 1
#define SERVICE_BUTTON_DEFAULT_RESET_HOLD_SEC 1500
#define SERVICE_BUTTON_DEFAULT_RESET_HOLD_SEC 10
static const char* DEVICE_NAME_PREFIX = "mqt-";
@ -177,7 +181,7 @@ static void onCommandRequest(const uint8_t* content, size_t ctLen,
static void onWifiConnected(void)
{
nxUpdateStatus(STATUS_OK);
nxUpdateStatus(serviceMode ? STATUS_OK_ALT : STATUS_OK);
if (wifiStarted) {
return;
@ -186,27 +190,29 @@ static void onWifiConnected(void)
wifiStarted = true;
systemSettings->deviceName = nxGetWifiDeviceName();
nxInitSntpClient(SNTP_RETRIES, systemSettings->sntpAddr, systemSettings->tzEnv);
if (!serviceMode) {
nxInitSntpClient(SNTP_RETRIES, systemSettings->sntpAddr, systemSettings->tzEnv);
strcpy(mqttSettings.brokerAddr, appSettings->mqttHost);
strcpy(mqttSettings.apiTopic, appSettings->mqttApiUri);
strcpy(mqttSettings.hbTopic, appSettings->mqttHbUri);
strcpy(mqttSettings.user, appSettings->mqttUser);
strcpy(mqttSettings.brokerAddr, appSettings->mqttHost);
strcpy(mqttSettings.apiTopic, appSettings->mqttApiUri);
strcpy(mqttSettings.hbTopic, appSettings->mqttHbUri);
strcpy(mqttSettings.user, appSettings->mqttUser);
strcpy(mqttSettings.password, appSettings->mqttPassword);
strcpy(mqttSettings.clientId, appSettings->overrideDevName
? appSettings->customDevName
: systemSettings->deviceName);
strcpy(mqttSettings.password, appSettings->mqttPassword);
strcpy(mqttSettings.clientId, appSettings->overrideDevName
? appSettings->customDevName
: systemSettings->deviceName);
mqttSettings.hbIntervalSec = appSettings->mqttHbIntervalSec;
mqttSettings.caCrt = appSettings->mqttUseTls ? appSettings->caCert : NULL;
mqttSettings.messageCb = onMqttMessage;
mqttSettings.connectedCb = onMqttConnected;
mqttSettings.disconnectedCb = onMqttDisconnected;
mqttSettings.errorCb = onMqttError;
mqttSettings.hbIntervalSec = appSettings->mqttHbIntervalSec;
mqttSettings.caCrt = appSettings->mqttUseTls ? appSettings->caCert : NULL;
mqttSettings.messageCb = onMqttMessage;
mqttSettings.connectedCb = onMqttConnected;
mqttSettings.disconnectedCb = onMqttDisconnected;
mqttSettings.errorCb = onMqttError;
if (!nxStartMqttClient(&mqttSettings)) {
onMqttError();
if (!nxStartMqttClient(&mqttSettings)) {
onMqttError();
}
}
nxSetMqTriggerHttpCallbacks(&httpCallbacks);
@ -297,7 +303,7 @@ static void hbTask(void* param)
static void connWatchdogTask(void* param)
{
if (appSettings->wdogMaxSec == 0) {
if (appSettings->wdogMaxSec == 0 || serviceMode) {
ESP_LOGI(TAG, "Connection watchdog disabled");
vTaskDelete(NULL);
return;
@ -315,14 +321,14 @@ static void connWatchdogTask(void* param)
ESP_LOGI(TAG, "Connection watchdog: DEVICE NOT CONNECTED TO WIFI/MQTT BROKER");
fails += 1;
if (fails >= MAX_FAILS) {
ESP_LOGW(TAG, "MAX CONNECTION FAILED CHECKS REACHED, REBOOTING");
ESP_LOGW(TAG, "MAX CONNECTION FAILED CHECKS REACHED (%i), REBOOTING", MAX_FAILS);
esp_restart();
}
}
else if (fails > 0){
fails = 0;
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(WD_DELAY_SEC * 1000/ portTICK_PERIOD_MS);
}
}

4
main/MqtriggerApp.h

@ -1,3 +1,7 @@
// Copyright (c) 2020 Lukasz Chodyla
// Distributed under the MIT License.
// See accompanying file LICENSE.txt for the full license.
#ifndef MAIN_MQTRIGGERAPP_H_
#define MAIN_MQTRIGGERAPP_H_

2
main/static/index.html

@ -39,7 +39,7 @@
<footer>
<div class="container">
<p>
MqTrigger 2022
MqTrigger v1.1 2022
</p>
</div>
</footer>

6
main/static/index.js

@ -56,7 +56,7 @@ function loadContent(url) {
http.send();
}
function fillInputs(jsonString) {
function fillInputs(element, jsonString) {
let obj = JSON.parse(jsonString);
if (obj) {
for (var key of Object.keys(obj)) {
@ -82,7 +82,7 @@ function loadValues(element) {
}
if (valuesCache[srcUrl]) {
fillInputs(valuesCache[srcUrl]);
fillInputs(element, valuesCache[srcUrl]);
continue;
}
@ -95,7 +95,7 @@ function loadValues(element) {
http.onreadystatechange = function () {//Call a function when the state changes.
if (http.readyState == 4 && http.status == 200) {
valuesCache[srcUrl] = http.responseText;
fillInputs(http.responseText);
fillInputs(element, http.responseText);
}
}
http.send();

2
main/static/min/index.html

@ -1 +1 @@
<meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon type=image/png href=data:image/png,%89PNG%0D%0A%1A%0A><link rel=stylesheet href=index.css><script src=index.js></script><title>MqTrigger web panel</title><header class="sticky row"><div class="container nav-bar"><ul><li><a id=app-btn href=# role=button class=nav-btn data-dst=/app/form>Application</a><li><a href=# role=button class=nav-btn data-dst=/sys/form>System</a></ul></div></header><div class=container><div class=col-md-offset-1 id=content><h1>Loading</h1><p>Loading content... Please make sure that JavaScript is enabled.</div></div><hr><footer><div class=container><p>MqTrigger 2022</div></footer><script>initNavButtons();document.getElementById('app-btn').click();</script>
<meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon type=image/png href=data:image/png,%89PNG%0D%0A%1A%0A><link rel=stylesheet href=index.css><script src=index.js></script><title>MqTrigger web panel</title><header class="sticky row"><div class="container nav-bar"><ul><li><a id=app-btn href=# role=button class=nav-btn data-dst=/app/form>Application</a><li><a href=# role=button class=nav-btn data-dst=/sys/form>System</a></ul></div></header><div class=container><div class=col-md-offset-1 id=content><h1>Loading</h1><p>Loading content... Please make sure that JavaScript is enabled.</div></div><hr><footer><div class=container><p>MqTrigger v1.1 2022</div></footer><script>initNavButtons();document.getElementById('app-btn').click();</script>

6
main/static/min/index.js

@ -5,10 +5,10 @@ else{console.log("Ignoring "+element.name);}}});postParams(form.getAttribute('ac
function initFormSendButtons(form){const btns=form.querySelectorAll('.send');for(i=0;i<btns.length;++i){btns[i].addEventListener('click',sendClickHandler);}}
function loadContent(url){let http=new XMLHttpRequest();http.open('GET',url,true);let element=document.getElementById('content');element.innerHTML="LOADING...";http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){element.innerHTML=http.responseText;loadValues(element);initFormSendButtons(element);}}
http.send();}
function fillInputs(jsonString){let obj=JSON.parse(jsonString);if(obj){for(var key of Object.keys(obj)){let input=element.querySelector("[name='"+key+"'");if(input){input.value=obj[key];if(input.hasAttribute('data-onset')){eval(input.getAttribute("data-onset"));}}}}}
function fillInputs(element,jsonString){let obj=JSON.parse(jsonString);if(obj){for(var key of Object.keys(obj)){let input=element.querySelector("[name='"+key+"'");if(input){input.value=obj[key];if(input.hasAttribute('data-onset')){eval(input.getAttribute("data-onset"));}}}}}
function loadValues(element){valuesCache={};const forms=element.querySelectorAll('form');for(i=0;i<forms.length;++i){const srcUrl=forms[i].getAttribute('data-values-src');if(!srcUrl){continue;}
if(valuesCache[srcUrl]){fillInputs(valuesCache[srcUrl]);continue;}
let http=new XMLHttpRequest();http.open('GET',srcUrl,false);http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){valuesCache[srcUrl]=http.responseText;fillInputs(http.responseText);}}
if(valuesCache[srcUrl]){fillInputs(element,valuesCache[srcUrl]);continue;}
let http=new XMLHttpRequest();http.open('GET',srcUrl,false);http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){valuesCache[srcUrl]=http.responseText;fillInputs(element,http.responseText);}}
http.send();}}
function postParams(url,params){var http=new XMLHttpRequest();http.open('POST',url,true);http.setRequestHeader('Content-type','application/x-www-form-urlencoded');http.onreadystatechange=function(){if(http.readyState==4&&http.status==200){alert(http.responseText);}}
http.send(params);}

Loading…
Cancel
Save