Compare commits
6 Commits
1e306e68d0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f3d60b9adb | |||
| 5f26731a3f | |||
| 7c6177cd40 | |||
| 4be7876cce | |||
| 76260212d2 | |||
| 6fd45c2a8f |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Artifacts
|
||||
*_secrets.h
|
||||
_build
|
||||
version.h
|
||||
|
||||
# Binaries
|
||||
*.FCStd1
|
||||
*.stl
|
||||
5
.vscode/arduino.json
vendored
Normal file
5
.vscode/arduino.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sketch": "window_control/window_control.ino",
|
||||
"configuration": "BoardModel=primo,xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200",
|
||||
"board": "esp8266:esp8266:arduino-esp8266"
|
||||
}
|
||||
272
.vscode/c_cpp_properties.json
vendored
Normal file
272
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
{
|
||||
"version": 4,
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Arduino",
|
||||
"compilerPath": "/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/xtensa-lx106-elf-g++",
|
||||
"compilerArgs": [
|
||||
"-U__STRICT_ANSI__",
|
||||
"-w",
|
||||
"-mlongcalls",
|
||||
"-mtext-section-literals",
|
||||
"-fno-rtti",
|
||||
"-falign-functions=4",
|
||||
"-std=gnu++11"
|
||||
],
|
||||
"intelliSenseMode": "gcc-x64",
|
||||
"includePath": [
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/sdk/include",
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/sdk/lwip2/include",
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/sdk/libc/xtensa-lx106-elf/include",
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266",
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/variants/arduino_spi",
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266WiFi/src",
|
||||
"/home/joe/Arduino/libraries/PubSubClient/src",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/c++/4.8.2",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/c++/4.8.2/xtensa-lx106-elf",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include/c++/4.8.2/backward",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/lib/gcc/xtensa-lx106-elf/4.8.2/include-fixed",
|
||||
"/home/joe/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/xtensa-lx106-elf/include"
|
||||
],
|
||||
"forcedInclude": [
|
||||
"/home/joe/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266/Arduino.h"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++11",
|
||||
"defines": [
|
||||
"__ets__",
|
||||
"ICACHE_FLASH",
|
||||
"NONOSDK22x_190703=1",
|
||||
"F_CPU=80000000L",
|
||||
"LWIP_OPEN_SRC",
|
||||
"TCP_MSS=536",
|
||||
"LWIP_FEATURES=1",
|
||||
"LWIP_IPV6=0",
|
||||
"ARDUINO=10813",
|
||||
"ARDUINO_ESP8266_ARDUINO_PRIMO",
|
||||
"ARDUINO_ARCH_ESP8266",
|
||||
"ARDUINO_BOARD=\"ESP8266_ARDUINO_PRIMO\"",
|
||||
"FLASHMODE_QIO",
|
||||
"F_CRYSTAL=40000000",
|
||||
"ESP8266",
|
||||
"__DBL_MIN_EXP__=(-1021)",
|
||||
"__UINT_LEAST16_MAX__=65535",
|
||||
"__ATOMIC_ACQUIRE=2",
|
||||
"__FLT_MIN__=1.1754943508222875e-38F",
|
||||
"__UINT_LEAST8_TYPE__=unsigned char",
|
||||
"__INTMAX_C(c)=c ## LL",
|
||||
"__CHAR_BIT__=8",
|
||||
"__UINT8_MAX__=255",
|
||||
"__WINT_MAX__=4294967295U",
|
||||
"__ORDER_LITTLE_ENDIAN__=1234",
|
||||
"__SIZE_MAX__=4294967295U",
|
||||
"__WCHAR_MAX__=65535",
|
||||
"__DBL_DENORM_MIN__=double(4.9406564584124654e-324L)",
|
||||
"__GCC_ATOMIC_CHAR_LOCK_FREE=1",
|
||||
"__FLT_EVAL_METHOD__=0",
|
||||
"__GCC_ATOMIC_CHAR32_T_LOCK_FREE=1",
|
||||
"__UINT_FAST64_MAX__=18446744073709551615ULL",
|
||||
"__SIG_ATOMIC_TYPE__=int",
|
||||
"__DBL_MIN_10_EXP__=(-307)",
|
||||
"__FINITE_MATH_ONLY__=0",
|
||||
"__GNUC_PATCHLEVEL__=2",
|
||||
"__UINT_FAST8_MAX__=4294967295U",
|
||||
"__DEC64_MAX_EXP__=385",
|
||||
"__INT8_C(c)=c",
|
||||
"__UINT_LEAST64_MAX__=18446744073709551615ULL",
|
||||
"__SHRT_MAX__=32767",
|
||||
"__LDBL_MAX__=1.7976931348623157e+308L",
|
||||
"__UINT_LEAST8_MAX__=255",
|
||||
"__GCC_ATOMIC_BOOL_LOCK_FREE=1",
|
||||
"__UINTMAX_TYPE__=long long unsigned int",
|
||||
"__DEC32_EPSILON__=1E-6DF",
|
||||
"__CHAR_UNSIGNED__=1",
|
||||
"__UINT32_MAX__=4294967295UL",
|
||||
"__LDBL_MAX_EXP__=1024",
|
||||
"__WINT_MIN__=0U",
|
||||
"__SCHAR_MAX__=127",
|
||||
"__WCHAR_MIN__=0",
|
||||
"__INT64_C(c)=c ## LL",
|
||||
"__DBL_DIG__=15",
|
||||
"__GCC_ATOMIC_POINTER_LOCK_FREE=1",
|
||||
"__XTENSA_CALL0_ABI__=1",
|
||||
"__SIZEOF_INT__=4",
|
||||
"__SIZEOF_POINTER__=4",
|
||||
"__GCC_ATOMIC_CHAR16_T_LOCK_FREE=1",
|
||||
"__USER_LABEL_PREFIX__",
|
||||
"__STDC_HOSTED__=1",
|
||||
"__LDBL_HAS_INFINITY__=1",
|
||||
"__XTENSA_EL__=1",
|
||||
"__FLT_EPSILON__=1.1920928955078125e-7F",
|
||||
"__GXX_WEAK__=1",
|
||||
"__LDBL_MIN__=2.2250738585072014e-308L",
|
||||
"__DEC32_MAX__=9.999999E96DF",
|
||||
"__INT32_MAX__=2147483647L",
|
||||
"__SIZEOF_LONG__=4",
|
||||
"__UINT16_C(c)=c",
|
||||
"__DECIMAL_DIG__=17",
|
||||
"__LDBL_HAS_QUIET_NAN__=1",
|
||||
"__GNUC__=4",
|
||||
"__GXX_RTTI=1",
|
||||
"__FLT_HAS_DENORM__=1",
|
||||
"__SIZEOF_LONG_DOUBLE__=8",
|
||||
"__BIGGEST_ALIGNMENT__=16",
|
||||
"__DBL_MAX__=double(1.7976931348623157e+308L)",
|
||||
"__INT_FAST32_MAX__=2147483647",
|
||||
"__DBL_HAS_INFINITY__=1",
|
||||
"__INT64_MAX__=9223372036854775807LL",
|
||||
"__DEC32_MIN_EXP__=(-94)",
|
||||
"__INT_FAST16_TYPE__=int",
|
||||
"__LDBL_HAS_DENORM__=1",
|
||||
"__cplusplus=199711L",
|
||||
"__DEC128_MAX__=9.999999999999999999999999999999999E6144DL",
|
||||
"__INT_LEAST32_MAX__=2147483647L",
|
||||
"__DEC32_MIN__=1E-95DF",
|
||||
"__DEPRECATED=1",
|
||||
"__DBL_MAX_EXP__=1024",
|
||||
"__DEC128_EPSILON__=1E-33DL",
|
||||
"__PTRDIFF_MAX__=2147483647",
|
||||
"__GNUG__=4",
|
||||
"__LONG_LONG_MAX__=9223372036854775807LL",
|
||||
"__SIZEOF_SIZE_T__=4",
|
||||
"__SIZEOF_WINT_T__=4",
|
||||
"__GXX_ABI_VERSION=1002",
|
||||
"__FLT_MIN_EXP__=(-125)",
|
||||
"__INT_FAST64_TYPE__=long long int",
|
||||
"__DBL_MIN__=double(2.2250738585072014e-308L)",
|
||||
"__FLT_MIN_10_EXP__=(-37)",
|
||||
"__DEC128_MIN__=1E-6143DL",
|
||||
"__REGISTER_PREFIX__",
|
||||
"__UINT16_MAX__=65535",
|
||||
"__DBL_HAS_DENORM__=1",
|
||||
"__UINT8_TYPE__=unsigned char",
|
||||
"__NO_INLINE__=1",
|
||||
"__FLT_MANT_DIG__=24",
|
||||
"__VERSION__=\"4.8.2\"",
|
||||
"__UINT64_C(c)=c ## ULL",
|
||||
"__XTENSA_SOFT_FLOAT__=1",
|
||||
"__GCC_ATOMIC_INT_LOCK_FREE=1",
|
||||
"__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__",
|
||||
"__INT32_C(c)=c ## L",
|
||||
"__DEC64_EPSILON__=1E-15DD",
|
||||
"__ORDER_PDP_ENDIAN__=3412",
|
||||
"__DEC128_MIN_EXP__=(-6142)",
|
||||
"__INT_FAST32_TYPE__=int",
|
||||
"__UINT_LEAST16_TYPE__=short unsigned int",
|
||||
"__INT16_MAX__=32767",
|
||||
"__SIZE_TYPE__=unsigned int",
|
||||
"__UINT64_MAX__=18446744073709551615ULL",
|
||||
"__INT8_TYPE__=signed char",
|
||||
"__ELF__=1",
|
||||
"__xtensa__=1",
|
||||
"__FLT_RADIX__=2",
|
||||
"__INT_LEAST16_TYPE__=short int",
|
||||
"__LDBL_EPSILON__=2.2204460492503131e-16L",
|
||||
"__UINTMAX_C(c)=c ## ULL",
|
||||
"__SIG_ATOMIC_MAX__=2147483647",
|
||||
"__GCC_ATOMIC_WCHAR_T_LOCK_FREE=1",
|
||||
"__SIZEOF_PTRDIFF_T__=4",
|
||||
"__DEC32_SUBNORMAL_MIN__=0.000001E-95DF",
|
||||
"__INT_FAST16_MAX__=2147483647",
|
||||
"__UINT_FAST32_MAX__=4294967295U",
|
||||
"__UINT_LEAST64_TYPE__=long long unsigned int",
|
||||
"__FLT_HAS_QUIET_NAN__=1",
|
||||
"__FLT_MAX_10_EXP__=38",
|
||||
"__LONG_MAX__=2147483647L",
|
||||
"__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL",
|
||||
"__FLT_HAS_INFINITY__=1",
|
||||
"__UINT_FAST16_TYPE__=unsigned int",
|
||||
"__DEC64_MAX__=9.999999999999999E384DD",
|
||||
"__CHAR16_TYPE__=short unsigned int",
|
||||
"__PRAGMA_REDEFINE_EXTNAME=1",
|
||||
"__INT_LEAST16_MAX__=32767",
|
||||
"__DEC64_MANT_DIG__=16",
|
||||
"__UINT_LEAST32_MAX__=4294967295UL",
|
||||
"__GCC_ATOMIC_LONG_LOCK_FREE=1",
|
||||
"__INT_LEAST64_TYPE__=long long int",
|
||||
"__INT16_TYPE__=short int",
|
||||
"__INT_LEAST8_TYPE__=signed char",
|
||||
"__DEC32_MAX_EXP__=97",
|
||||
"__INT_FAST8_MAX__=2147483647",
|
||||
"__INTPTR_MAX__=2147483647",
|
||||
"__EXCEPTIONS=1",
|
||||
"__LDBL_MANT_DIG__=53",
|
||||
"__DBL_HAS_QUIET_NAN__=1",
|
||||
"__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)",
|
||||
"__INTPTR_TYPE__=int",
|
||||
"__UINT16_TYPE__=short unsigned int",
|
||||
"__WCHAR_TYPE__=short unsigned int",
|
||||
"__SIZEOF_FLOAT__=4",
|
||||
"__UINTPTR_MAX__=4294967295U",
|
||||
"__DEC64_MIN_EXP__=(-382)",
|
||||
"__INT_FAST64_MAX__=9223372036854775807LL",
|
||||
"__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1",
|
||||
"__FLT_DIG__=6",
|
||||
"__UINT_FAST64_TYPE__=long long unsigned int",
|
||||
"__INT_MAX__=2147483647",
|
||||
"__INT64_TYPE__=long long int",
|
||||
"__FLT_MAX_EXP__=128",
|
||||
"__DBL_MANT_DIG__=53",
|
||||
"__INT_LEAST64_MAX__=9223372036854775807LL",
|
||||
"__DEC64_MIN__=1E-383DD",
|
||||
"__WINT_TYPE__=unsigned int",
|
||||
"__UINT_LEAST32_TYPE__=long unsigned int",
|
||||
"__SIZEOF_SHORT__=2",
|
||||
"__LDBL_MIN_EXP__=(-1021)",
|
||||
"__INT_LEAST8_MAX__=127",
|
||||
"__WCHAR_UNSIGNED__=1",
|
||||
"__LDBL_MAX_10_EXP__=308",
|
||||
"__ATOMIC_RELAXED=0",
|
||||
"__DBL_EPSILON__=double(2.2204460492503131e-16L)",
|
||||
"__UINT8_C(c)=c",
|
||||
"__INT_LEAST32_TYPE__=long int",
|
||||
"__SIZEOF_WCHAR_T__=2",
|
||||
"__UINT64_TYPE__=long long unsigned int",
|
||||
"__INT_FAST8_TYPE__=int",
|
||||
"__DBL_DECIMAL_DIG__=17",
|
||||
"__DEC_EVAL_METHOD__=2",
|
||||
"__XTENSA__=1",
|
||||
"__ORDER_BIG_ENDIAN__=4321",
|
||||
"__UINT32_C(c)=c ## UL",
|
||||
"__INTMAX_MAX__=9223372036854775807LL",
|
||||
"__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__",
|
||||
"__FLT_DENORM_MIN__=1.4012984643248171e-45F",
|
||||
"__INT8_MAX__=127",
|
||||
"__UINT_FAST32_TYPE__=unsigned int",
|
||||
"__CHAR32_TYPE__=long unsigned int",
|
||||
"__FLT_MAX__=3.4028234663852886e+38F",
|
||||
"__INT32_TYPE__=long int",
|
||||
"__SIZEOF_DOUBLE__=8",
|
||||
"__INTMAX_TYPE__=long long int",
|
||||
"__DEC128_MAX_EXP__=6145",
|
||||
"__ATOMIC_CONSUME=1",
|
||||
"__GNUC_MINOR__=8",
|
||||
"__UINTMAX_MAX__=18446744073709551615ULL",
|
||||
"__DEC32_MANT_DIG__=7",
|
||||
"__DBL_MAX_10_EXP__=308",
|
||||
"__LDBL_DENORM_MIN__=4.9406564584124654e-324L",
|
||||
"__INT16_C(c)=c",
|
||||
"__STDC__=1",
|
||||
"__PTRDIFF_TYPE__=int",
|
||||
"__ATOMIC_SEQ_CST=5",
|
||||
"__UINT32_TYPE__=long unsigned int",
|
||||
"__UINTPTR_TYPE__=unsigned int",
|
||||
"__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD",
|
||||
"__DEC128_MANT_DIG__=34",
|
||||
"__LDBL_MIN_10_EXP__=(-307)",
|
||||
"__SIZEOF_LONG_LONG__=8",
|
||||
"__GCC_ATOMIC_LLONG_LOCK_FREE=1",
|
||||
"__LDBL_DIG__=15",
|
||||
"__FLT_DECIMAL_DIG__=9",
|
||||
"__UINT_FAST16_MAX__=4294967295U",
|
||||
"__GNUC_GNU_INLINE__=1",
|
||||
"__GCC_ATOMIC_SHORT_LOCK_FREE=1",
|
||||
"__UINT_FAST8_TYPE__=unsigned int",
|
||||
"__ATOMIC_ACQ_REL=4",
|
||||
"__ATOMIC_RELEASE=3",
|
||||
"USBCON"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
116
window_control/firmware/Makefile
Normal file
116
window_control/firmware/Makefile
Normal file
@@ -0,0 +1,116 @@
|
||||
# Kitsune Scientific
|
||||
|
||||
# What project to build
|
||||
PROJ := firmware
|
||||
|
||||
|
||||
# What board to build for and its core
|
||||
CORE ?= esp8266:esp8266
|
||||
FQBN ?= esp8266:esp8266:generic
|
||||
|
||||
# Tools, their links and versions
|
||||
ARDUINO_CLI_VERSION :=
|
||||
ARDUINO_CLI_URL := https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh
|
||||
ARDUINO_LINT_VERSION :=
|
||||
ARDUINO_LINT_URL := https://raw.githubusercontent.com/arduino/arduino-lint/main/etc/install.sh
|
||||
|
||||
# The version and time we're compiling from
|
||||
GIT_VERSION := "$(shell git describe --abbrev=4 --dirty --always --tags)"
|
||||
COMPILED_DATE := "$(shell date)"
|
||||
|
||||
# Treat all warnings as errors.
|
||||
BUILDPROP := compiler.warning_flags.all='-Wall -Wextra -Werror'
|
||||
|
||||
# Locations
|
||||
ROOT := $(PWD)
|
||||
BINDIR := $(ROOT)/_build/bin
|
||||
BUILDDIR := $(ROOT)/_build
|
||||
|
||||
# What port to build on
|
||||
ifndef SERIAL_DEV
|
||||
ifneq (,$(wildcard /dev/ttyUSB0))
|
||||
SERIAL_DEV = /dev/ttyUSB0
|
||||
else ifneq (,$(wildcard /dev/ttyACM0))
|
||||
SERIAL_DEV = /dev/ttyACM0
|
||||
else
|
||||
SERIAL_DEV = unknown
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
.PHONY: all help build upload version release requirements
|
||||
|
||||
# Do everything
|
||||
all: tools requirements version build
|
||||
|
||||
|
||||
help:
|
||||
@echo
|
||||
@echo "Targets:"
|
||||
@echo " lint De-lint the software."
|
||||
@echo " build Build the software."
|
||||
@echo " upload Upload the software."
|
||||
@echo " requirements Fetch all requirements."
|
||||
@echo
|
||||
|
||||
|
||||
# Set VERBOSE=1 to not run in --silent
|
||||
|
||||
ifndef VERBOSE
|
||||
.SILENT:
|
||||
endif
|
||||
|
||||
# Only build the code
|
||||
build: version $(PROJ).ino
|
||||
$(BINDIR)/arduino-cli core install $(CORE)
|
||||
$(BINDIR)/arduino-cli compile -b $(FQBN) $(PROJ)
|
||||
|
||||
# Make binaries
|
||||
bin: tools requirements version $(PROJ).ino
|
||||
$(BINDIR)/arduino-cli core install $(CORE)
|
||||
$(BINDIR)/arduino-cli compile -b $(FQBN) $(PROJ) -e
|
||||
|
||||
# Clean and rename (could be optimized)
|
||||
mv build/* _build
|
||||
rm -rv build
|
||||
|
||||
# Only upload the software
|
||||
upload: version build $(PROJ).ino
|
||||
$(BINDIR)/arduino-cli upload -b $(FQBN) $(PROJ) -p $(SERIAL_DEV)
|
||||
|
||||
# Only update the version
|
||||
version:
|
||||
echo "#define VERSION \"$(GIT_VERSION)\"" > version.h
|
||||
echo "#define COMPILED_ON \"$(COMPILED_DATE)\"" >> version.h
|
||||
|
||||
# Generate an artifact
|
||||
release: build $(PROJ).ino
|
||||
$(BINDIR)/arduino-cli compile -b $(FQBN) $(PROJ) --output-dir $(BUILDDIR)
|
||||
|
||||
# Only fetch the requirements
|
||||
requirements:
|
||||
@if [ -e requirements.txt ]; \
|
||||
then while read -r i ; do echo ; \
|
||||
echo "---> Installing " '"'$$i'"' ; \
|
||||
$(BINDIR)/arduino-cli lib install "$$i" ; \
|
||||
done < requirements.txt ; \
|
||||
else echo "---> MISSING requirements.txt file"; \
|
||||
fi
|
||||
|
||||
# Monitor the serial (debug) output.
|
||||
# Requires minicom
|
||||
monitor: upload
|
||||
minicom -D $(SERIAL_DEV) -b 115200
|
||||
|
||||
lint: tools
|
||||
$(BINDIR)/arduino-lint --compliance strict
|
||||
|
||||
# Fetches all the tools required
|
||||
tools:
|
||||
mkdir -p $(BINDIR)
|
||||
curl -fsSL $(ARDUINO_CLI_URL) | BINDIR=$(BINDIR) sh -s $(ARDUINO_CLI_VERSION)
|
||||
curl -fsSL $(ARDUINO_LINT_URL) | BINDIR=$(BINDIR) sh -s $(ARDUINO_LINT_VERSION)
|
||||
|
||||
# Messy, come back and fix?
|
||||
clean:
|
||||
rm -rv _build/arduino.avr.mega
|
||||
8
window_control/firmware/README.md
Normal file
8
window_control/firmware/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# To install
|
||||
|
||||
You will have to add `https://arduino.esp8266.com/stable/package_esp8266com_index.json` to your arduino-cli.yaml
|
||||
|
||||
```shell
|
||||
arduino-cli config init
|
||||
vim ~/.arduino15/arduino-cli.yaml
|
||||
```
|
||||
105
window_control/firmware/firmware.ino
Normal file
105
window_control/firmware/firmware.ino
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
// WiFi
|
||||
const char *ssid = "internet_of_insecure_things";
|
||||
const char *wifi_password = "iamnotacrook";
|
||||
|
||||
// MQTT
|
||||
const char *clientID = "window_0"; // Unique to this device
|
||||
|
||||
const char *mqtt_server = "mqtt.kitsunehosting.net";
|
||||
const char *mqtt_topic = "home/upstairs_lab/actuators/window_0";
|
||||
const char *mqtt_username = "admin";
|
||||
const char *mqtt_password = "iamnotacrook";
|
||||
|
||||
// Initialise the WiFi and MQTT Client objects
|
||||
WiFiClient wifiClient;
|
||||
PubSubClient client(mqtt_server, 1883, wifiClient); // 1883 is the listener port for the Broker
|
||||
|
||||
void setup()
|
||||
{
|
||||
// pinMode(ledPin, OUTPUT);
|
||||
|
||||
// Switch the on-board LED off to start with
|
||||
// digitalWrite(ledPin, HIGH);
|
||||
|
||||
// Begin Serial on 115200
|
||||
// Remember to choose the correct Baudrate on the Serial monitor!
|
||||
// This is just for debugging purposes
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
// Connect to the WiFi
|
||||
WiFi.begin(ssid, wifi_password);
|
||||
|
||||
// Wait until the connection has been confirmed before continuing
|
||||
while (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("WiFi connected");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Configure client callback
|
||||
client.setCallback(callback);
|
||||
}
|
||||
|
||||
void reconnect()
|
||||
{
|
||||
/* Reconnects to the MQTT Server */
|
||||
if (client.connect(clientID, mqtt_username, mqtt_password))
|
||||
{
|
||||
Serial.println("Connected to MQTT Broker!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Connection to MQTT Broker failed...");
|
||||
}
|
||||
|
||||
client.publish("test", "0");
|
||||
|
||||
// What to listen for
|
||||
client.subscribe("test");
|
||||
}
|
||||
|
||||
void callback(char *topic, byte *payload, unsigned int length)
|
||||
{
|
||||
Serial.print("Message arrived in topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
Serial.print("Message:");
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
Serial.print((char)payload[i]);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(600);
|
||||
|
||||
// digitalWrite(ledPin, HIGH);
|
||||
if (client.publish(mqtt_topic, "1"))
|
||||
{
|
||||
Serial.println("Button pushed and message sent!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Message failed to send. Reconnecting to MQTT Broker and trying again");
|
||||
reconnect();
|
||||
delay(10);
|
||||
client.publish(mqtt_topic, "-1");
|
||||
}
|
||||
|
||||
tone(5, 1200, 300);
|
||||
|
||||
client.loop(); // Runs cleanup, etc on client
|
||||
}
|
||||
2
window_control/firmware/pinout.h
Normal file
2
window_control/firmware/pinout.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define WINDOW_CLOSE = 5
|
||||
#define WINDOW_OPEN = 6
|
||||
1
window_control/firmware/requirements.txt
Normal file
1
window_control/firmware/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
PubSubClient
|
||||
BIN
window_control/models/Automatic Gearbox Electronics Mount.FCStd
Normal file
BIN
window_control/models/Automatic Gearbox Electronics Mount.FCStd
Normal file
Binary file not shown.
@@ -1,97 +0,0 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
#define wifi_ssid "muner"
|
||||
#define wifi_password "Ah ah ah, you didn't say the magic word."
|
||||
|
||||
#define mqtt_server "mqtt.kitsunehosting.net"
|
||||
#define mqtt_port 1883
|
||||
#define mqtt_user "device"
|
||||
#define mqtt_password "iamnotacrook"
|
||||
|
||||
#define in_topic "/testing/in"
|
||||
#define out_topic "/testing/out"
|
||||
// Replace by 2 if you aren't enable to use Serial Monitor... Don't forget to Rewire R1 to GPIO2!
|
||||
#define in_led 2
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
setup_wifi();
|
||||
client.setClient(espClient);
|
||||
client.setServer(mqtt_server, mqtt_port);
|
||||
client.setCallback(callback);
|
||||
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
pinMode(in_led, OUTPUT);
|
||||
digitalWrite(in_led, HIGH);
|
||||
}
|
||||
|
||||
void setup_wifi() {
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
WiFi.hostname("ESP-Test1");
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(wifi_ssid);
|
||||
|
||||
WiFi.begin(wifi_ssid, wifi_password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.println("Not yet connected.. Waiting 500ms to check again..");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void reconnect() {
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
// If you do not want to use a username and password, change next line to
|
||||
// if (client.connect("ESP8266Client")) {
|
||||
if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
|
||||
Serial.println("connected");
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
Serial.print("Message arrived [");
|
||||
Serial.print(topic);
|
||||
Serial.print("] ");
|
||||
for (int i = 0; i < length; i++) {
|
||||
char receivedChar = (char)payload[i];
|
||||
Serial.print(receivedChar);
|
||||
if (receivedChar == '0')
|
||||
digitalWrite(in_led, LOW);
|
||||
if (receivedChar == '1')
|
||||
digitalWrite(in_led, HIGH);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
// Publishes a random 0 and 1 like someone switching off and on randomly (random(2))
|
||||
client.publish(out_topic, String(random(2)).c_str(), true);
|
||||
delay(1000);
|
||||
client.subscribe(in_topic);
|
||||
delay(1000);
|
||||
}
|
||||
Reference in New Issue
Block a user