commit a40177bd7ad9499fe2ea9409b7493a59c5a7dda7 Author: gutmet Date: Tue Feb 28 17:22:46 2023 +0100 preliminary results for trap alarm diff --git a/TrapAlarm/.vscode/arduino.json b/TrapAlarm/.vscode/arduino.json new file mode 100644 index 0000000..8550cfa --- /dev/null +++ b/TrapAlarm/.vscode/arduino.json @@ -0,0 +1,7 @@ +{ + "configuration": "xtal=80,vt=flash,exception=disabled,stacksmash=disabled,ssl=all,mmu=3232,non32xfer=fast,eesz=4M2M,led=2,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200", + "board": "esp8266:esp8266:nodemcuv2", + "sketch": "ESP8266_SIM800L.ino", + "output": "../build", + "port": "/dev/ttyUSB0" +} \ No newline at end of file diff --git a/TrapAlarm/.vscode/c_cpp_properties.json b/TrapAlarm/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..bb51e0b --- /dev/null +++ b/TrapAlarm/.vscode/c_cpp_properties.json @@ -0,0 +1,385 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Linux", + "compilerPath": "/usr/bin/gcc", + "compilerArgs": [], + "intelliSenseMode": "linux-gcc-x64", + "includePath": [ + "${workspaceFolder}/**", + "/home/alexander/Arduino/libraries/**", + "/home/alexander/arduino-1.8.19/**", + "/home/alexander/.arduino15/packages/esp8266/**", + "/home/alexander/Arduino/build/core" + ], + "forcedInclude": [], + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "defines": [ + "USBCON" + ] + }, + { + "name": "Arduino", + "compilerPath": "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/xtensa-lx106-elf-g++", + "compilerArgs": [ + "-U__STRICT_ANSI__", + "-w", + "-Werror=return-type", + "-free", + "-fipa-pta", + "-mlongcalls", + "-mtext-section-literals", + "-fno-rtti", + "-falign-functions=4", + "-std=gnu++17" + ], + "intelliSenseMode": "gcc-x64", + "includePath": [ + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/sdk/include", + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/sdk/lwip2/include", + "/home/alexander/Arduino/build/core", + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266", + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/variants/nodemcu", + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/libraries/SoftwareSerial/src", + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/libraries/ESP8266WiFi/src", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/xtensa-lx106-elf", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include/c++/10.3.0/backward", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/lib/gcc/xtensa-lx106-elf/10.3.0/include", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/lib/gcc/xtensa-lx106-elf/10.3.0/include-fixed", + "/home/alexander/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/xtensa-lx106-elf/include" + ], + "forcedInclude": [ + "/home/alexander/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/cores/esp8266/Arduino.h" + ], + "cStandard": "c11", + "cppStandard": "c++17", + "defines": [ + "__ets__", + "ICACHE_FLASH", + "_GNU_SOURCE", + "MMU_IRAM_SIZE=0x8000", + "MMU_ICACHE_SIZE=0x8000", + "NONOSDK22x_190703=1", + "F_CPU=80000000L", + "LWIP_OPEN_SRC", + "TCP_MSS=536", + "LWIP_FEATURES=1", + "LWIP_IPV6=0", + "ARDUINO=10819", + "ARDUINO_ESP8266_NODEMCU_ESP12E", + "ARDUINO_ARCH_ESP8266", + "ARDUINO_BOARD=\"ESP8266_NODEMCU_ESP12E\"", + "LED_BUILTIN=2", + "FLASHMODE_DIO", + "ESP8266", + "__DBL_MIN_EXP__=(-1021)", + "__cpp_attributes=200809L", + "__UINT_LEAST16_MAX__=0xffff", + "__ATOMIC_ACQUIRE=2", + "__FLT_MIN__=1.1754943508222875e-38F", + "__GCC_IEC_559_COMPLEX=0", + "__cpp_aggregate_nsdmi=201304L", + "__UINT_LEAST8_TYPE__=unsigned char", + "__INTMAX_C(c)=c ## LL", + "__CHAR_BIT__=8", + "__UINT8_MAX__=0xff", + "__WINT_MAX__=0xffffffffU", + "__FLT32_MIN_EXP__=(-125)", + "__cpp_static_assert=200410L", + "__ORDER_LITTLE_ENDIAN__=1234", + "__SIZE_MAX__=0xffffffffU", + "__WCHAR_MAX__=0xffff", + "__DBL_DENORM_MIN__=double(4.9406564584124654e-324L)", + "__GCC_ATOMIC_CHAR_LOCK_FREE=1", + "__GCC_IEC_559=0", + "__FLT32X_DECIMAL_DIG__=17", + "__FLT_EVAL_METHOD__=0", + "__cpp_binary_literals=201304L", + "__FLT64_DECIMAL_DIG__=17", + "__GCC_ATOMIC_CHAR32_T_LOCK_FREE=1", + "__cpp_variadic_templates=200704L", + "__UINT_FAST64_MAX__=0xffffffffffffffffULL", + "__SIG_ATOMIC_TYPE__=int", + "__DBL_MIN_10_EXP__=(-307)", + "__FINITE_MATH_ONLY__=0", + "__cpp_variable_templates=201304L", + "__FLT32X_MAX_EXP__=1024", + "__GNUC_PATCHLEVEL__=0", + "__FLT32_HAS_DENORM__=1", + "__UINT_FAST8_MAX__=0xffffffffU", + "__cpp_rvalue_reference=200610L", + "__FLT32_MAX_10_EXP__=38", + "__INT8_C(c)=c", + "__INT_LEAST8_WIDTH__=8", + "__UINT_LEAST64_MAX__=0xffffffffffffffffULL", + "__SHRT_MAX__=0x7fff", + "__LDBL_MAX__=1.7976931348623157e+308L", + "__UINT_LEAST8_MAX__=0xff", + "__GCC_ATOMIC_BOOL_LOCK_FREE=1", + "__UINTMAX_TYPE__=long long unsigned int", + "__FLT_EVAL_METHOD_TS_18661_3__=0", + "__CHAR_UNSIGNED__=1", + "__UINT32_MAX__=0xffffffffU", + "__GXX_EXPERIMENTAL_CXX0X__=1", + "__LDBL_MAX_EXP__=1024", + "__WINT_MIN__=0U", + "__INT_LEAST16_WIDTH__=16", + "__SCHAR_MAX__=0x7f", + "__WCHAR_MIN__=0", + "__INT64_C(c)=c ## LL", + "__GCC_ATOMIC_POINTER_LOCK_FREE=1", + "__XTENSA_CALL0_ABI__=1", + "__SIZEOF_INT__=4", + "__FLT32X_MANT_DIG__=53", + "__GCC_ATOMIC_CHAR16_T_LOCK_FREE=1", + "__USER_LABEL_PREFIX__", + "__STDC_HOSTED__=1", + "__XTENSA_EL__=1", + "__cpp_decltype_auto=201304L", + "__DBL_DIG__=15", + "__FLT32_DIG__=6", + "__FLT_EPSILON__=1.1920928955078125e-7F", + "__GXX_WEAK__=1", + "__SHRT_WIDTH__=16", + "__LDBL_MIN__=2.2250738585072014e-308L", + "__cpp_threadsafe_static_init=200806L", + "__FLT32X_HAS_INFINITY__=1", + "__INT32_MAX__=0x7fffffff", + "__INT_WIDTH__=32", + "__SIZEOF_LONG__=4", + "__UINT16_C(c)=c", + "__DECIMAL_DIG__=17", + "__FLT64_EPSILON__=2.2204460492503131e-16F64", + "__INT16_MAX__=0x7fff", + "__FLT64_MIN_EXP__=(-1021)", + "__LDBL_HAS_QUIET_NAN__=1", + "__FLT64_MANT_DIG__=53", + "__GNUC__=10", + "__GXX_RTTI=1", + "__FLT_HAS_DENORM__=1", + "__SIZEOF_LONG_DOUBLE__=8", + "__BIGGEST_ALIGNMENT__=16", + "__STDC_UTF_16__=1", + "__FLT64_MAX_10_EXP__=308", + "__cpp_delegating_constructors=200604L", + "__FLT32_HAS_INFINITY__=1", + "__DBL_MAX__=double(1.7976931348623157e+308L)", + "__cpp_raw_strings=200710L", + "__INT_FAST32_MAX__=0x7fffffff", + "__DBL_HAS_INFINITY__=1", + "__HAVE_SPECULATION_SAFE_VALUE=1", + "__INTPTR_WIDTH__=32", + "__UINT_LEAST32_MAX__=0xffffffffU", + "__FLT32X_HAS_DENORM__=1", + "__INT_FAST16_TYPE__=int", + "__LDBL_HAS_DENORM__=1", + "__cplusplus=201402L", + "__cpp_ref_qualifiers=200710L", + "__INT_LEAST32_MAX__=0x7fffffff", + "__DEPRECATED=1", + "__cpp_rvalue_references=200610L", + "__DBL_MAX_EXP__=1024", + "__WCHAR_WIDTH__=16", + "__FLT32_MAX__=3.4028234663852886e+38F32", + "__GCC_ATOMIC_LONG_LOCK_FREE=1", + "__PTRDIFF_MAX__=0x7fffffff", + "__FLT32_HAS_QUIET_NAN__=1", + "__GNUG__=10", + "__LONG_LONG_MAX__=0x7fffffffffffffffLL", + "__SIZEOF_SIZE_T__=4", + "__cpp_nsdmi=200809L", + "__SIZEOF_WINT_T__=4", + "__LONG_LONG_WIDTH__=64", + "__cpp_initializer_lists=200806L", + "__FLT32_MAX_EXP__=128", + "__cpp_hex_float=201603L", + "__GXX_ABI_VERSION=1014", + "__FLT_MIN_EXP__=(-125)", + "__cpp_lambdas=200907L", + "__INT_FAST64_TYPE__=long long int", + "__FLT64_DENORM_MIN__=4.9406564584124654e-324F64", + "__DBL_MIN__=double(2.2250738585072014e-308L)", + "__SIZEOF_POINTER__=4", + "__SIZE_TYPE__=unsigned int", + "__DBL_HAS_QUIET_NAN__=1", + "__FLT32X_EPSILON__=2.2204460492503131e-16F32x", + "__FLT64_MIN_10_EXP__=(-307)", + "__REGISTER_PREFIX__", + "__UINT16_MAX__=0xffff", + "__FLT32_MIN__=1.1754943508222875e-38F32", + "__UINT8_TYPE__=unsigned char", + "__FLT_DIG__=6", + "__NO_INLINE__=1", + "__DEC_EVAL_METHOD__=2", + "__FLT_MANT_DIG__=24", + "__LDBL_DECIMAL_DIG__=17", + "__VERSION__=\"10.3.0\"", + "__UINT64_C(c)=c ## ULL", + "__cpp_unicode_characters=200704L", + "__XTENSA_SOFT_FLOAT__=1", + "__GCC_ATOMIC_INT_LOCK_FREE=1", + "__FLT32_MANT_DIG__=24", + "__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__SCHAR_WIDTH__=8", + "__INT32_C(c)=c", + "__ORDER_PDP_ENDIAN__=3412", + "__INT_FAST32_TYPE__=int", + "__UINT_LEAST16_TYPE__=short unsigned int", + "__DBL_HAS_DENORM__=1", + "__cpp_rtti=199711L", + "__UINT64_MAX__=0xffffffffffffffffULL", + "__INT8_TYPE__=signed char", + "__cpp_digit_separators=201309L", + "__ELF__=1", + "__xtensa__=1", + "__FLT_RADIX__=2", + "__INT_LEAST16_TYPE__=short int", + "__LDBL_EPSILON__=2.2204460492503131e-16L", + "__UINTMAX_C(c)=c ## ULL", + "__FLT32X_MIN__=2.2250738585072014e-308F32x", + "__SIG_ATOMIC_MAX__=0x7fffffff", + "__GCC_ATOMIC_WCHAR_T_LOCK_FREE=1", + "__SIZEOF_PTRDIFF_T__=4", + "__LDBL_DIG__=15", + "__FLT32X_MIN_EXP__=(-1021)", + "__INT_FAST16_MAX__=0x7fffffff", + "__FLT64_DIG__=15", + "__UINT_FAST32_MAX__=0xffffffffU", + "__UINT_LEAST64_TYPE__=long long unsigned int", + "__FLT_HAS_QUIET_NAN__=1", + "__FLT_MAX_10_EXP__=38", + "__LONG_MAX__=0x7fffffffL", + "__FLT_HAS_INFINITY__=1", + "__cpp_unicode_literals=200710L", + "__UINT_FAST16_TYPE__=unsigned int", + "__INT_FAST32_WIDTH__=32", + "__CHAR16_TYPE__=short unsigned int", + "__PRAGMA_REDEFINE_EXTNAME=1", + "__SIZE_WIDTH__=32", + "__INT_LEAST16_MAX__=0x7fff", + "__INT64_MAX__=0x7fffffffffffffffLL", + "__FLT32_DENORM_MIN__=1.4012984643248171e-45F32", + "__SIG_ATOMIC_WIDTH__=32", + "__INT_LEAST64_TYPE__=long long int", + "__INT16_TYPE__=short int", + "__INT_LEAST8_TYPE__=signed char", + "__INT_FAST8_MAX__=0x7fffffff", + "__INTPTR_MAX__=0x7fffffff", + "__cpp_sized_deallocation=201309L", + "__FLT64_HAS_QUIET_NAN__=1", + "__FLT32_MIN_10_EXP__=(-37)", + "__EXCEPTIONS=1", + "__PTRDIFF_WIDTH__=32", + "__LDBL_MANT_DIG__=53", + "__cpp_range_based_for=200907L", + "__FLT64_HAS_INFINITY__=1", + "__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)", + "__cpp_return_type_deduction=201304L", + "__INTPTR_TYPE__=int", + "__UINT16_TYPE__=short unsigned int", + "__WCHAR_TYPE__=short unsigned int", + "__SIZEOF_FLOAT__=4", + "__UINTPTR_MAX__=0xffffffffU", + "__INT_FAST64_WIDTH__=64", + "__cpp_decltype=200707L", + "__FLT32_DECIMAL_DIG__=9", + "__INT_FAST64_MAX__=0x7fffffffffffffffLL", + "__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1", + "__FLT_NORM_MAX__=3.4028234663852886e+38F", + "__UINT_FAST64_TYPE__=long long unsigned int", + "__INT_MAX__=0x7fffffff", + "__INT64_TYPE__=long long int", + "__FLT_MAX_EXP__=128", + "__DBL_MANT_DIG__=53", + "__cpp_inheriting_constructors=201511L", + "__INT_LEAST64_MAX__=0x7fffffffffffffffLL", + "__WINT_TYPE__=unsigned int", + "__UINT_LEAST32_TYPE__=unsigned int", + "__SIZEOF_SHORT__=2", + "__FLT32_NORM_MAX__=3.4028234663852886e+38F32", + "__LDBL_MIN_EXP__=(-1021)", + "__FLT64_MAX__=1.7976931348623157e+308F64", + "__WINT_WIDTH__=32", + "__INT_LEAST8_MAX__=0x7f", + "__INT_LEAST64_WIDTH__=64", + "__FLT32X_MAX_10_EXP__=308", + "__WCHAR_UNSIGNED__=1", + "__LDBL_MAX_10_EXP__=308", + "__ATOMIC_RELAXED=0", + "__DBL_EPSILON__=double(2.2204460492503131e-16L)", + "__UINT8_C(c)=c", + "__FLT64_MAX_EXP__=1024", + "__INT_LEAST32_TYPE__=int", + "__SIZEOF_WCHAR_T__=2", + "__FLT64_NORM_MAX__=1.7976931348623157e+308F64", + "__INTMAX_MAX__=0x7fffffffffffffffLL", + "__INT_FAST8_TYPE__=int", + "__LDBL_HAS_INFINITY__=1", + "__GNUC_STDC_INLINE__=1", + "__FLT64_HAS_DENORM__=1", + "__FLT32_EPSILON__=1.1920928955078125e-7F32", + "__DBL_DECIMAL_DIG__=17", + "__STDC_UTF_32__=1", + "__INT_FAST8_WIDTH__=32", + "__FLT32X_MAX__=1.7976931348623157e+308F32x", + "__DBL_NORM_MAX__=double(1.7976931348623157e+308L)", + "__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__", + "__XTENSA__=1", + "__INTMAX_WIDTH__=64", + "__ORDER_BIG_ENDIAN__=4321", + "__cpp_runtime_arrays=198712L", + "__UINT64_TYPE__=long long unsigned int", + "__UINT32_C(c)=c ## U", + "__cpp_alias_templates=200704L", + "__FLT_DENORM_MIN__=1.4012984643248171e-45F", + "__INT8_MAX__=0x7f", + "__LONG_WIDTH__=32", + "__UINT_FAST32_TYPE__=unsigned int", + "__FLT32X_NORM_MAX__=1.7976931348623157e+308F32x", + "__CHAR32_TYPE__=unsigned int", + "__FLT_MAX__=3.4028234663852886e+38F", + "__cpp_constexpr=201304L", + "__INT32_TYPE__=int", + "__SIZEOF_DOUBLE__=8", + "__cpp_exceptions=199711L", + "__FLT_MIN_10_EXP__=(-37)", + "__FLT64_MIN__=2.2250738585072014e-308F64", + "__INT_LEAST32_WIDTH__=32", + "__INTMAX_TYPE__=long long int", + "__FLT32X_HAS_QUIET_NAN__=1", + "__ATOMIC_CONSUME=1", + "__GNUC_MINOR__=3", + "__INT_FAST16_WIDTH__=32", + "__UINTMAX_MAX__=0xffffffffffffffffULL", + "__FLT32X_DENORM_MIN__=4.9406564584124654e-324F32x", + "__DBL_MAX_10_EXP__=308", + "__LDBL_DENORM_MIN__=4.9406564584124654e-324L", + "__INT16_C(c)=c", + "__STDC__=1", + "__FLT32X_DIG__=15", + "__PTRDIFF_TYPE__=int", + "__ATOMIC_SEQ_CST=5", + "__UINT32_TYPE__=unsigned int", + "__FLT32X_MIN_10_EXP__=(-307)", + "__UINTPTR_TYPE__=unsigned int", + "__LDBL_MIN_10_EXP__=(-307)", + "__cpp_generic_lambdas=201304L", + "__SIZEOF_LONG_LONG__=8", + "__cpp_user_defined_literals=200809L", + "__GCC_ATOMIC_LLONG_LOCK_FREE=1", + "__FLT_DECIMAL_DIG__=9", + "__UINT_FAST16_MAX__=0xffffffffU", + "__LDBL_NORM_MAX__=1.7976931348623157e+308L", + "__GCC_ATOMIC_SHORT_LOCK_FREE=1", + "__UINT_FAST8_TYPE__=unsigned int", + "__cpp_init_captures=201304L", + "__ATOMIC_ACQ_REL=4", + "__ATOMIC_RELEASE=3", + "USBCON" + ] + } + ] +} \ No newline at end of file diff --git a/TrapAlarm/ESP8266_SIM800L.ino b/TrapAlarm/ESP8266_SIM800L.ino new file mode 100644 index 0000000..c94aa39 --- /dev/null +++ b/TrapAlarm/ESP8266_SIM800L.ino @@ -0,0 +1,113 @@ +#include +#include +#include + +#define SERIAL2_TX_D6 12 +#define SERIAL2_RX_D7 13 +#define SERIAL_DELAY 200 +#define DEBUG_D1 5 +#define ONBOARD_LED 16 +#define ERROR_BLINK_DELAY 200 + +const char* ssid = "gutmetmetihmseindings"; +const char* wifipassword = "321meins"; +const uint16_t serverport = 666; +IPAddress local_IP(192,168,0,1); +IPAddress gateway(0,0,0,0); +IPAddress subnet(255,255,255,0); +WiFiServer server(serverport); +WiFiClient client; + +SoftwareSerial myPort; + +bool debugMode = true; // false; +bool okSIM = true; +bool ledOn = false; + +void determineDebugMode() { + pinMode(DEBUG_D1, INPUT_PULLUP); + pinMode(ONBOARD_LED, OUTPUT); + digitalWrite(ONBOARD_LED, LOW); + delay(100); + if (digitalRead(DEBUG_D1) == LOW) + debugMode = true; +} + +void setupAP() { + if (debugMode) { + WiFi.softAPConfig(local_IP, gateway, subnet); + WiFi.softAP(ssid, wifipassword); + } +} + +void setupSoftSerial() { + // SIM 800L comm + myPort.begin(9600, SWSERIAL_8N1, SERIAL2_RX_D7, SERIAL2_TX_D6, false); + if (!myPort) + while (true) + delay(1000); +} + +void setupDebugServer() { + if (debugMode) { + server.begin(); + do + client = server.available(); + while (!client); + } +} + +String sendCmd(String cmd) { + myPort.println(cmd); + delay(SERIAL_DELAY); + return myPort.readString(); +} + +bool sendCmdAndExpect(String cmd, String expected) { + String response = sendCmd(cmd); + if (expected != NULL && expected != "") + return response.indexOf(expected) > -1; + else + return true; +} + +void checkSIMModule() { + if (!debugMode) { + okSIM &= sendCmdAndExpect("ATI", "SIM800"); + okSIM &= sendCmdAndExpect("AT+CREG?", "+CREG: 0,1"); + String resp = sendCmd("AT+CSQ"); + int first = resp.indexOf(":"); + int last = resp.indexOf(","); + if (first > -1 && last > -1 && (last-1) > first) { + String tmp = resp.substring(first+1, last); + tmp.trim(); + int val = tmp.toInt(); + okSIM &= (val > 10); + } + } +} + +void setup() { + determineDebugMode(); + setupAP(); + setupSoftSerial(); + setupDebugServer(); + checkSIMModule(); +} + +void loop() { + if (debugMode) { + while (client.available() == 0) {} + String cmd = client.readString(); + cmd.trim(); + myPort.println(cmd); + delay(333); + client.println(myPort.readString()); + } else if (!okSIM) { + ledOn = !ledOn; + digitalWrite(ONBOARD_LED, ledOn); + delay(ERROR_BLINK_DELAY); + } else { + + } +} \ No newline at end of file