├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Changelog.md ├── README.env ├── README.hacking ├── README.md ├── SENSORLOGGER.md ├── cmake └── cross-compile.cmake ├── configs └── config_default ├── coverity_configs ├── g++-config-0 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++-config-1 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++-config-2 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++-config-3 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++cc-config-0 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++cc-config-1 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++cc-config-2 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── g++cc-config-3 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── gcc-config-0 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml ├── gcc-config-1 │ ├── coverity-compiler-compat.h │ ├── coverity-macro-compat.h │ └── coverity_config.xml └── xtensa.xml ├── html ├── css │ └── jquery.terminal.min.css ├── index.html └── js │ ├── jquery-1.7.2.min.js │ ├── jquery.mousewheel-min.js │ ├── jquery.terminal.min.js │ └── keyboardevent-key-polyfill.js ├── include ├── base64.h ├── cbuf.h ├── cbuftools.h ├── console.h ├── driver │ ├── adc.h │ ├── dht22.h │ ├── ds18b20.h │ ├── gpio16.h │ ├── i2c_at24eep.h │ ├── i2c_bh1750.h │ ├── i2c_bmp180.h │ ├── i2c_hd44780.h │ ├── i2c_hmc5883l.h │ ├── i2c_ina219.h │ ├── i2c_master.h │ ├── i2c_mlx90614.h │ ├── i2c_pcf8591.h │ ├── i2c_sht21.h │ ├── i2c_si7020.h │ ├── i2c_tcs3414cs.h │ ├── key.h │ ├── lcd_config.h │ ├── pwm.h │ ├── spi_master.h │ ├── spi_register.h │ ├── uart.h │ └── uart_register.h ├── env.h ├── esp_systemapi.h ├── espmissingincludes.h ├── flash_layout.h ├── generic │ └── macros.h ├── heatshrink_common.h ├── heatshrink_config.h ├── heatshrink_decoder.h ├── helpers.h ├── hostname.h ├── httpdconfig.h ├── iwconnect.h ├── lib │ ├── config.h │ ├── debug.h │ ├── mqtt.h │ ├── mqtt_msg.h │ ├── proto.h │ ├── queue.h │ ├── ringbuf.h │ ├── tftp.h │ ├── typedef.h │ ├── user_config.h │ └── utils.h ├── main.h ├── microrl-config.h ├── microrl.h ├── missing.h ├── pin_map.h ├── sched.h ├── sensorlogger.h ├── svc_telnet.h ├── tcpservice.h └── user_config.h ├── kcnf ├── lds ├── eagle.app.v6.ld └── eagle.rom.addr.v6.ld ├── mkespfsimage ├── CMakeLists.txt ├── Makefile ├── espfsformat.h ├── heatshrink_encoder.c ├── main.c └── out.espfs ├── scripts └── iromify └── src ├── Makefile ├── base64.c ├── cbuf.c ├── cbuftools.c ├── cmd_adc.c ├── cmd_at.c ├── cmd_common.c ├── cmd_dht22.c ├── cmd_ds18b20.c ├── cmd_env.c ├── cmd_flash.c ├── cmd_gpio.c ├── cmd_i2c.c ├── cmd_ifconfig.c ├── cmd_iw.c ├── cmd_listen.c ├── cmd_mqtt.c ├── cmd_nslookup.c ├── cmd_passthrough.c ├── cmd_ping.c ├── cmd_send.c ├── cmd_tftp.c ├── cmd_uart.c ├── cmd_wiphy.c ├── console.c ├── console_auth.c ├── contrib ├── cbuftest.c ├── lwipupdate │ ├── diff-esp │ ├── diff-git │ ├── diff-git-repatch │ ├── gitid-lwip-esp.txt │ └── gitid-lwip-git.txt └── tcpechotester.c ├── env.c ├── esp-temp-lwip.c ├── esp_timer.c ├── flash_end_marker.c ├── heatshrink ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── dec_sm.dot ├── enc_sm.dot ├── greatest.h ├── heatshrink.c ├── heatshrink_decoder.c ├── heatshrink_encoder.c ├── heatshrink_encoder.h ├── test_heatshrink_dynamic.c ├── test_heatshrink_dynamic_theft.c └── test_heatshrink_static.c ├── helpers.c ├── hostname.c ├── httpd ├── auth.c ├── auth.h ├── base64.c ├── base64.h ├── cgi.c ├── cgi.h ├── cgiwifi.c ├── cgiwifi.h ├── config_store.c ├── config_store.h ├── cstdint.h ├── espfs.c ├── espfs.h ├── heatshrink_config_httpd.h ├── heatshrink_decoder.c ├── httpd.c ├── httpd.h ├── httpdespfs.c ├── httpdespfs.h ├── io.c ├── io.h ├── main.c ├── stdout.c ├── stdout.h ├── sysex.c ├── sysex.h ├── uart.c ├── uart.h └── user_main.c ├── i2c_at24eep.c ├── i2c_bh1750.c ├── i2c_bmp180.c ├── i2c_hd44780.c ├── i2c_hmc5883l.c ├── i2c_ina219.c ├── i2c_master.c ├── i2c_mlx90614.c ├── i2c_pcf8591.c ├── i2c_sht21.c ├── i2c_si7020.c ├── i2c_tcs3414cs.c ├── iwconnect.c ├── lwip-app ├── Makefile ├── dhcpserver.c ├── espconn.c ├── espconn_tcp.c ├── espconn_udp.c ├── not-compiled-netio.c └── not-compiled-ping.c ├── lwip-esp ├── Makefile ├── api │ ├── Makefile │ ├── api_lib.c │ ├── api_msg.c │ ├── err.c │ ├── netbuf.c │ ├── netdb.c │ ├── netifapi.c │ ├── sockets.c │ └── tcpip.c ├── core │ ├── Makefile │ ├── def.c │ ├── dhcp.c │ ├── dns.c │ ├── init.c │ ├── ipv4 │ │ ├── Makefile │ │ ├── autoip.c │ │ ├── icmp.c │ │ ├── igmp.c │ │ ├── inet.c │ │ ├── inet_chksum.c │ │ ├── ip.c │ │ ├── ip_addr.c │ │ └── ip_frag.c │ ├── mem.c │ ├── memp.c │ ├── netif.c │ ├── pbuf.c │ ├── raw.c │ ├── stats.c │ ├── sys.c │ ├── tcp.c │ ├── tcp_in.c │ ├── tcp_out.c │ ├── timers.c │ └── udp.c ├── include │ ├── ipv4 │ │ └── lwip │ │ │ ├── autoip.h │ │ │ ├── icmp.h │ │ │ ├── igmp.h │ │ │ ├── inet.h │ │ │ ├── inet_chksum.h │ │ │ ├── ip.h │ │ │ ├── ip_addr.h │ │ │ └── ip_frag.h │ ├── lwip │ │ ├── api.h │ │ ├── api_msg.h │ │ ├── arch.h │ │ ├── debug.h │ │ ├── def.h │ │ ├── dhcp.h │ │ ├── dns.h │ │ ├── err.h │ │ ├── init.h │ │ ├── mem.h │ │ ├── memp.h │ │ ├── memp_std.h │ │ ├── netbuf.h │ │ ├── netdb.h │ │ ├── netif.h │ │ ├── netifapi.h │ │ ├── opt.h │ │ ├── pbuf.h │ │ ├── raw.h │ │ ├── sio.h │ │ ├── snmp.h │ │ ├── snmp_asn1.h │ │ ├── snmp_msg.h │ │ ├── snmp_structs.h │ │ ├── sockets.h │ │ ├── stats.h │ │ ├── sys.h │ │ ├── tcp.h │ │ ├── tcp_impl.h │ │ ├── tcpip.h │ │ ├── timers.h │ │ └── udp.h │ └── netif │ │ ├── etharp.h │ │ └── ppp_oe.h └── netif │ ├── Makefile │ └── etharp.c ├── lwip-git ├── FILES ├── Makefile ├── api │ ├── Makefile │ ├── api_lib.c │ ├── api_msg.c │ ├── err.c │ ├── netbuf.c │ ├── netdb.c │ ├── netifapi.c │ ├── pppapi.c │ ├── sockets.c │ └── tcpip.c ├── core │ ├── Makefile │ ├── def.c │ ├── dhcp.c │ ├── dns.c │ ├── inet_chksum.c │ ├── init.c │ ├── ipv4 │ │ ├── Makefile │ │ ├── autoip.c │ │ ├── icmp.c │ │ ├── igmp.c │ │ ├── ip4.c │ │ ├── ip4_addr.c │ │ └── ip_frag.c │ ├── ipv6 │ │ ├── README │ │ ├── dhcp6.c │ │ ├── ethip6.c │ │ ├── icmp6.c │ │ ├── inet6.c │ │ ├── ip6.c │ │ ├── ip6_addr.c │ │ ├── ip6_frag.c │ │ ├── mld6.c │ │ └── nd6.c │ ├── mem.c │ ├── memp.c │ ├── netif.c │ ├── pbuf.c │ ├── raw.c │ ├── snmp │ │ ├── asn1_dec.c │ │ ├── asn1_enc.c │ │ ├── mib2.c │ │ ├── mib_structs.c │ │ ├── msg_in.c │ │ └── msg_out.c │ ├── stats.c │ ├── sys.c │ ├── tcp.c │ ├── tcp_in.c │ ├── tcp_out.c │ ├── timers.c │ └── udp.c ├── include │ ├── lwip │ │ ├── api.h │ │ ├── api_msg.h │ │ ├── arch.h │ │ ├── autoip.h │ │ ├── debug.h │ │ ├── def.h │ │ ├── dhcp.h │ │ ├── dhcp6.h │ │ ├── dns.h │ │ ├── err.h │ │ ├── ethip6.h │ │ ├── icmp.h │ │ ├── icmp6.h │ │ ├── igmp.h │ │ ├── inet.h │ │ ├── inet_chksum.h │ │ ├── init.h │ │ ├── ip.h │ │ ├── ip4.h │ │ ├── ip4_addr.h │ │ ├── ip6.h │ │ ├── ip6_addr.h │ │ ├── ip6_frag.h │ │ ├── ip_addr.h │ │ ├── ip_frag.h │ │ ├── mem.h │ │ ├── memp.h │ │ ├── memp_std.h │ │ ├── mld6.h │ │ ├── nd6.h │ │ ├── netbuf.h │ │ ├── netdb.h │ │ ├── netif.h │ │ ├── netifapi.h │ │ ├── opt.h │ │ ├── pbuf.h │ │ ├── pppapi.h │ │ ├── raw.h │ │ ├── sio.h │ │ ├── snmp.h │ │ ├── snmp_asn1.h │ │ ├── snmp_msg.h │ │ ├── snmp_structs.h │ │ ├── sockets.h │ │ ├── stats.h │ │ ├── sys.h │ │ ├── tcp.h │ │ ├── tcp_impl.h │ │ ├── tcpip.h │ │ ├── timers.h │ │ └── udp.h │ ├── netif │ │ ├── etharp.h │ │ ├── ppp │ │ │ ├── ccp.h │ │ │ ├── chap-md5.h │ │ │ ├── chap-new.h │ │ │ ├── chap_ms.h │ │ │ ├── eap.h │ │ │ ├── ecp.h │ │ │ ├── eui64.h │ │ │ ├── fsm.h │ │ │ ├── ipcp.h │ │ │ ├── ipv6cp.h │ │ │ ├── lcp.h │ │ │ ├── magic.h │ │ │ ├── mppe.h │ │ │ ├── polarssl │ │ │ │ ├── arc4.h │ │ │ │ ├── des.h │ │ │ │ ├── md4.h │ │ │ │ ├── md5.h │ │ │ │ └── sha1.h │ │ │ ├── ppp.h │ │ │ ├── ppp_impl.h │ │ │ ├── pppcrypt.h │ │ │ ├── pppdebug.h │ │ │ ├── pppoe.h │ │ │ ├── pppol2tp.h │ │ │ ├── pppos.h │ │ │ ├── upap.h │ │ │ └── vj.h │ │ └── slipif.h │ └── posix │ │ ├── netdb.h │ │ └── sys │ │ └── socket.h └── netif │ ├── FILES │ ├── Makefile │ ├── etharp.c │ ├── ethernetif.c │ ├── ppp │ ├── PPPD_FOLLOWUP │ ├── auth.c │ ├── ccp.c │ ├── chap-md5.c │ ├── chap-new.c │ ├── chap_ms.c │ ├── demand.c │ ├── eap.c │ ├── ecp.c │ ├── eui64.c │ ├── fsm.c │ ├── ipcp.c │ ├── ipv6cp.c │ ├── lcp.c │ ├── magic.c │ ├── mppe.c │ ├── multilink.c │ ├── polarssl │ │ ├── README │ │ ├── arc4.c │ │ ├── des.c │ │ ├── md4.c │ │ ├── md5.c │ │ └── sha1.c │ ├── ppp.c │ ├── pppcrypt.c │ ├── pppoe.c │ ├── pppol2tp.c │ ├── pppos.c │ ├── upap.c │ ├── utils.c │ └── vj.c │ └── slipif.c ├── main.c ├── microrl.c ├── mqtt ├── Makefile ├── config.c ├── mqtt.c ├── mqtt_msg.c ├── proto.c ├── queue.c ├── ringbuf.c └── utils.c ├── netapps-is-not-compiled ├── Makefile ├── dhcpserver.c ├── espconn.c ├── espconn_tcp.c ├── espconn_udp.c ├── netio.c └── ping.c ├── newlib-dummies.c ├── pin_map.c ├── sched.c ├── sensorlogger.c ├── sensorloggers ├── adc.c ├── ping.c └── vdd3v3.c ├── stdio.c ├── svc_aura.c ├── svc_echo.c ├── svc_sensorlogger.c ├── svc_telnet.c ├── tcpservice.c ├── tftp.c ├── uart.c ├── user_config.h └── user_rf_cal_sector_set.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.gch 2 | antares 3 | build 4 | *~ 5 | #*# 6 | *.o 7 | *.d 8 | tmp 9 | *.bak 10 | *.old 11 | include/config 12 | include/generated 13 | images/ 14 | include/arch 15 | .config 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "auraclient"] 2 | path = lib/auraclient 3 | url = https://github.com/nekromant/auraclient.git 4 | [submodule "esp8266-json"] 5 | path = lib/esp8266-json 6 | url = https://github.com/osbean/esp8266-json.git 7 | [submodule "lib/esphttpclient"] 8 | path = lib/esphttpclient 9 | url = https://github.com/Caerbannog/esphttpclient.git 10 | [submodule "lib/esp8266_ping"] 11 | path = lib/esp8266_ping 12 | url = https://github.com/eadf/esp8266_ping.git 13 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | 0.3 2 | * Switched buildsystem to cmake 3 | * Update API to latest 2.0 SDK 4 | * Implemented 2-binary image generation 5 | * Autodetect proper environment address 6 | * Fix ping 7 | * Fix microrl quoting 8 | * senslogger: Implement nextcloud sensorlogger infrastructure 9 | * senslogger: Add adc sensor 10 | * senslogger: Add vdd3v3 sensor 11 | * Add http server functionality 12 | * tftp downloads to arbitrary flash areas 13 | * Add web-based commandline support 14 | * Basic telnet authentification support 15 | * Implement console charhandler API 16 | * Automated builds via jenkins 17 | -------------------------------------------------------------------------------- /README.env: -------------------------------------------------------------------------------- 1 | Environment parameters: 2 | ---------------------- 3 | 4 | Key: sta-mode 5 | 6 | Description: How should we bring up the interface in client mode? 7 | 8 | Value: dhcp 9 | Description: Use to DHCP to obtainan IP address. 10 | 11 | Value: static 12 | Description: Use information from sta-ip, sta-mask and sta-gw environment variables 13 | 14 | 15 | Key: sta-ip 16 | Description: See sta-mode 17 | 18 | Key: sta-mask 19 | Description: See sta-mode 20 | 21 | Key: sta-gw 22 | Description: See sta-mode 23 | 24 | 25 | Key: dhcps-enable 26 | Description: Enable DHCP server for in access point mode. Can be 1 or 0 27 | 28 | Key: sta-ip 29 | Description: Access point mode IP address 30 | 31 | Key: sta-mask 32 | Description: Access point mode netmask 33 | 34 | Key: sta-gw 35 | Description: Access point mode gateway address 36 | 37 | 38 | Key: hostname 39 | Description: hostname to use. For now affects only the command prompt. 40 | 41 | Key: default-mode 42 | Description: Default wireless mode to start in. -------------------------------------------------------------------------------- /cmake/cross-compile.cmake: -------------------------------------------------------------------------------- 1 | # This file assumes that you have a linaro abe-based toolchain 2 | # with a raspbian sysroot somewhere inside. This file also 3 | # takes care to trick pkg-config into searching only toolchain's sysroot for 4 | # the libraries 5 | 6 | if (NOT CMAKE_LIBRARY_PATH) 7 | SET(CMAKE_LIBRARY_PATH ${CROSS_COMPILE}) 8 | endif() 9 | 10 | SET(CMAKE_SYSTEM_NAME Generic) 11 | SET(CMAKE_SYSTEM_VERSION 1) 12 | SET(CMAKE_C_COMPILER_WORKS YES) 13 | SET(CMAKE_CXX_COMPILER_WORKS YES) 14 | 15 | if (CMAKE_CLANG_CROSS) 16 | set(CMAKE_C_COMPILER clang) 17 | set(CROSS_COMMON_FLAGS -target ${CROSS_COMPILE} -ccc-gcc-name ${CROSS_COMPILE}-gcc) 18 | endif() 19 | 20 | if (NOT CMAKE_C_COMPILER) 21 | SET(CMAKE_C_COMPILER ${CROSS_COMPILE}-gcc${CMAKE_EXECUTABLE_SUFFIX}) 22 | endif() 23 | 24 | if (NOT CMAKE_C_COMPILER) 25 | SET(CMAKE_CXX_COMPILER ${CROSS_COMPILE}-g++${CMAKE_EXECUTABLE_SUFFIX}) 26 | endif() 27 | 28 | # where is the target environment 29 | # This macro should be called once AFTER PROJECT() directive 30 | macro(CROSS_COMPILE_DETECT_SYSROOT) 31 | find_program(CROSS_TOOLCHAIN_PATH NAMES ${CMAKE_C_COMPILER}) 32 | get_filename_component(CROSS_TOOLCHAIN_PATH "${CROSS_TOOLCHAIN_PATH}" PATH) 33 | 34 | if (EXISTS ${CROSS_TOOLCHAIN_PATH}/../${CROSS_COMPILE}/sysroot) 35 | SET(CMAKE_FIND_ROOT_PATH ${CROSS_TOOLCHAIN_PATH}/../${CROSS_COMPILE}/sysroot) 36 | elseif(EXISTS ${CROSS_TOOLCHAIN_PATH}/../${CROSS_COMPILE}/libc) 37 | SET(CMAKE_FIND_ROOT_PATH ${CROSS_TOOLCHAIN_PATH}/../${CROSS_COMPILE}/libc) 38 | else() 39 | message(WARNING "Couldn't auto-detect sysroot dir") 40 | endif() 41 | 42 | # search for programs in the build host directories 43 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 44 | # for libraries and headers in the target directories 45 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 46 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 47 | endmacro() 48 | -------------------------------------------------------------------------------- /configs/config_default: -------------------------------------------------------------------------------- 1 | # 2 | # Automatically generated file; DO NOT EDIT. 3 | # Configuration 4 | # 5 | 6 | # 7 | # LWIP 8 | # 9 | CONFIG_LWIP_ESP=y 10 | # CONFIG_LWIP_GIT is not set 11 | 12 | # 13 | # Hacks 14 | # 15 | CONFIG_ESP8266_NEED_ESPCONN_INIT=y 16 | 17 | # 18 | # Services to build 19 | # 20 | # CONFIG_SERVICE_DHCPS is not set 21 | CONFIG_SVC_HTTPD=y 22 | CONFIG_SERVICE_AURA=y 23 | CONFIG_SERVICE_SENSORLOGGER=y 24 | CONFIG_SENSLOG_DUMMY=y 25 | CONFIG_SENSLOG_PING=y 26 | CONFIG_SENSLOG_VDD3V3=y 27 | CONFIG_SENSLOG_ADC=y 28 | CONFIG_SERVICE_TCP=y 29 | CONFIG_SERVICE_TELNET=y 30 | # CONFIG_SERVICE_ECHO is not set 31 | 32 | # 33 | # Modules to build 34 | # 35 | CONFIG_CMD_IW=y 36 | CONFIG_CMD_PHY=y 37 | CONFIG_CMD_UART=y 38 | CONFIG_CMD_IF=y 39 | # CONFIG_CMD_GPIO is not set 40 | CONFIG_CMD_FLASH=y 41 | CONFIG_CMD_LISTEN=y 42 | CONFIG_CMD_SEND=y 43 | CONFIG_CMD_NSLOOKUP=y 44 | CONFIG_CMD_PING=y 45 | CONFIG_CMD_TFTP=y 46 | CONFIG_ENV_DEFAULT_TFTP_SERVER_IP="192.168.1.215" 47 | CONFIG_ENV_DEFAULT_TFTP_SERVER_DIR="/" 48 | CONFIG_ENV_DEFAULT_TFTP_SERVER_FILE="antares.com" 49 | CONFIG_CMD_AT=y 50 | CONFIG_CMD_ADC=y 51 | # CONFIG_CMD_I2C is not set 52 | # CONFIG_CMD_DHT22 is not set 53 | # CONFIG_ENABLE_MQTT is not set 54 | CONFIG_ENABLE_SCHED=y 55 | # CONFIG_ENABLE_PASSTHROUGH is not set 56 | # CONFIG_CMD_DS18B20 is not set 57 | 58 | # 59 | # Commandline fine-tuning 60 | # 61 | CONFIG_ENV_DEFAULT_PROMPT="frankenstein" 62 | CONFIG_MICRORL_USE_COMPLETE=y 63 | CONFIG_MICRORL_USE_HISTORY=y 64 | 65 | # 66 | # Environment Settings 67 | # 68 | CONFIG_ENV_OFFSET=0x7a000 69 | CONFIG_ENV_LEN=0x1000 70 | CONFIG_ADDR_BLOBSETTING1=0x7c000 71 | CONFIG_ADDR_BLOBSETTING2=0x7e000 72 | # CONFIG_ENV_NOWRITE is not set 73 | 74 | # 75 | # Default Values 76 | # 77 | # CONFIG_WIFI_MODE_AP is not set 78 | # CONFIG_WIFI_MODE_STATION is not set 79 | CONFIG_WIFI_MODE_SOFTAP=y 80 | # CONFIG_WIFI_MODE_NONE is not set 81 | CONFIG_ENV_DEFAULT_HOSTNAME="frankenstein" 82 | CONFIG_ENV_DEFAULT_STATION_IP="192.168.0.123" 83 | CONFIG_ENV_DEFAULT_STATION_MASK="255.255.255.0" 84 | CONFIG_ENV_DEFAULT_STATION_GW="192.168.0.1" 85 | CONFIG_ENV_DEFAULT_AP_IP="192.168.1.1" 86 | CONFIG_ENV_DEFAULT_AP_MASK="255.255.255.0" 87 | CONFIG_ENV_DEFAULT_AP_GW="192.168.1.1" 88 | CONFIG_ENV_DEFAULT_TELNET_AUTOSTART=n 89 | CONFIG_ENV_DEFAULT_TELNET_PORT=23 90 | CONFIG_ENV_DEFAULT_TELNET_DROP=60 91 | # CONFIG_ENABLE_SECOND_UART is not set 92 | CONFIG_ENABLE_BANNER=y 93 | -------------------------------------------------------------------------------- /coverity_configs/xtensa.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 1 6 | 7 | $CONFIGDIR$/gcc-config-0/coverity_config.xml 8 | $CONFIGDIR$/g++-config-0/coverity_config.xml 9 | $CONFIGDIR$/g++cc-config-0/coverity_config.xml 10 | $CONFIGDIR$/g++-config-1/coverity_config.xml 11 | $CONFIGDIR$/g++cc-config-1/coverity_config.xml 12 | $CONFIGDIR$/gcc-config-1/coverity_config.xml 13 | $CONFIGDIR$/g++-config-2/coverity_config.xml 14 | $CONFIGDIR$/g++cc-config-2/coverity_config.xml 15 | $CONFIGDIR$/g++-config-3/coverity_config.xml 16 | $CONFIGDIR$/g++cc-config-3/coverity_config.xml 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ESP8266 Frankenstein Web Shell 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /html/js/jquery.mousewheel-min.js: -------------------------------------------------------------------------------- 1 | (function(c){function g(a){var b=a||window.event,i=[].slice.call(arguments,1),e=0,h=0,f=0;a=c.event.fix(b);a.type="mousewheel";if(b.wheelDelta)e=b.wheelDelta/120;if(b.detail)e=-b.detail/3;f=e;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){f=0;h=-1*e}if(b.wheelDeltaY!==undefined)f=b.wheelDeltaY/120;if(b.wheelDeltaX!==undefined)h=-1*b.wheelDeltaX/120;i.unshift(a,e,h,f);return(c.event.dispatch||c.event.handle).apply(this,i)}var d=["DOMMouseScroll","mousewheel"];if(c.event.fixHooks)for(var j=d.length;j;)c.event.fixHooks[d[--j]]= 2 | c.event.mouseHooks;c.event.special.mousewheel={setup:function(){if(this.addEventListener)for(var a=d.length;a;)this.addEventListener(d[--a],g,false);else this.onmousewheel=g},teardown:function(){if(this.removeEventListener)for(var a=d.length;a;)this.removeEventListener(d[--a],g,false);else this.onmousewheel=null}};c.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})})(jQuery); 3 | -------------------------------------------------------------------------------- /include/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64_H 2 | #define BASE64_H 3 | 4 | /* 5 | base64.c - by Joe DF (joedf@ahkscript.org) 6 | Released under the MIT License 7 | 8 | Revision: 2015-06-12 01:26:51 9 | 10 | Thank you for inspiration: 11 | http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode 12 | */ 13 | 14 | 15 | 16 | //Base64 char table function - used internally for decoding 17 | unsigned int b64_int(unsigned int ch); 18 | 19 | // in_size : the number bytes to be encoded. 20 | // Returns the recommended memory size to be allocated for the output buffer excluding the null byte 21 | unsigned int b64e_size(unsigned int in_size); 22 | 23 | // in_size : the number bytes to be decoded. 24 | // Returns the recommended memory size to be allocated for the output buffer 25 | unsigned int b64d_size(unsigned int in_size); 26 | 27 | // in : buffer of "raw" binary to be encoded. 28 | // in_len : number of bytes to be encoded. 29 | // out : pointer to buffer with enough memory, user is responsible for memory allocation, receives null-terminated string 30 | // returns size of output including null byte 31 | unsigned int b64_encode(const char* in, unsigned int in_len, unsigned char* out); 32 | 33 | // in : buffer of base64 string to be decoded. 34 | // in_len : number of bytes to be decoded. 35 | // out : pointer to buffer with enough memory, user is responsible for memory allocation, receives "raw" binary 36 | // returns size of output excluding null byte 37 | unsigned int b64_decode(const unsigned char* in, unsigned int in_len, unsigned int* out); 38 | 39 | 40 | 41 | #endif /* end of include guard: BASE64_H */ 42 | -------------------------------------------------------------------------------- /include/cbuftools.h: -------------------------------------------------------------------------------- 1 | #ifndef _CBTOOLS_H_ 2 | #define _CBTOOLS_H_ 3 | 4 | #include 5 | 6 | #include "cbuf.h" 7 | 8 | // was 128 but flash_scan help line is bigger: 9 | #define SPRINTBUFSIZE 256 10 | 11 | extern char sprintbuf__ [SPRINTBUFSIZE]; 12 | 13 | void tooshortbuf (char* str, size_t size); 14 | int cbuf_printf (cbuf_t* cb, const char* fmt, ...) __attribute__ ((format (printf, 2, 3))); 15 | int cbuf_vprintf (cbuf_t* cb, const char* fmt, va_list ap); 16 | 17 | #endif // _CBTOOLS_H_ 18 | -------------------------------------------------------------------------------- /include/console.h: -------------------------------------------------------------------------------- 1 | #ifndef CONSOLE_H 2 | #define CONSOLE_H 3 | 4 | #define ESC_SPACE 300000 5 | #define ESC_COUNT 3 6 | 7 | struct console_cmd { 8 | const char *name; 9 | const char *help; 10 | int required_args; 11 | int maximum_args; 12 | int (*handler)(int argc, const char * const * argv); 13 | char ** (*get_completion) (int argc, const char * const * argv ); 14 | void (*interrupt)(void); 15 | } ; 16 | 17 | #define CONSOLE_CMD(_name, _reqargs, _maxargs, _handler, _inthandler, _completion, _help) \ 18 | struct console_cmd cmd_ ##_name \ 19 | __attribute__ ((used)) \ 20 | __attribute__((section(".console_cmd"))) = { \ 21 | .name = #_name, \ 22 | .required_args = _reqargs, \ 23 | .maximum_args = _maxargs, \ 24 | .handler = _handler, \ 25 | .interrupt = _inthandler, \ 26 | .get_completion = _completion, \ 27 | .help = _help, \ 28 | } 29 | 30 | 31 | #define SERIAL_PRINTF ets_uart_printf 32 | 33 | #define ENABLE_PASSTHROUGH_AT_BOOT 0 34 | 35 | #define LOG_ERR 0 36 | #define LOG_WARN 1 37 | #define LOG_NOTICE 2 38 | #define LOG_DEBUG 3 39 | #define LOG_DEBUG2 4 // very verbose 40 | #define LOG_LEVEL_MAX 99 41 | 42 | // LOG_LEVEL_MAX: print code will not be compiled if given level is higher 43 | //#define LOG_LEVEL_DEFAULT LOG_NOTICE 44 | #define LOG_LEVEL_DEFAULT LOG_LEVEL_MAX 45 | 46 | extern int log_level; 47 | #define set_log_level(lvl) do { log_level = (lvl); } while (0) 48 | #define __BASEFILE__ (strrchr(__FILE__, '/')?:__FILE__) 49 | #define LOGN(level,b...) do { if ((level) <= LOG_LEVEL_MAX && (level) <= log_level) { console_printf("%s: ", loglevnam(level)); console_printf(b); console_printf("\n"); } } while (0) 50 | #define LOGSERIALN(level,b...) do { if ((level) <= LOG_LEVEL_MAX && (level) <= log_level) { SERIAL_PRINTF("%s: ", loglevnam(level)); SERIAL_PRINTF(b); SERIAL_PRINTF("\n"); } } while (0) 51 | #define LOG(level,b...) do { if ((level) <= LOG_LEVEL_MAX && (level) <= log_level) { console_printf("%s: ", loglevnam(level)); console_printf(b); console_printf(" (%s:%d)\n", __BASEFILE__, __LINE__); } } while (0) 52 | #define LOGSERIAL(level,b...) do { if ((level) <= LOG_LEVEL_MAX && (level) <= log_level) { SERIAL_PRINTF("%s: ", loglevnam(level)); SERIAL_PRINTF(b); SERIAL_PRINTF(" (%s:%d)\n", __BASEFILE__, __LINE__); } } while (0) 53 | 54 | typedef int (*printf_f)(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); 55 | 56 | // add this to antares/esp8266 missing includes 57 | #include 58 | #include 59 | int vsnprintf(char *str, size_t size, const char *format, va_list ap); 60 | 61 | #include 62 | extern printf_f console_printf; 63 | 64 | #define HELPSTR_NEWLINE "\n " 65 | 66 | void console_init(int qlen); 67 | void console_insert(char c); 68 | void console_lock(int l); 69 | void console_write(char *buf, int len); 70 | void console_exec(char *str); 71 | void console_set_charhandler( void (*charhndlr)(void* arg, char c), void *arg); 72 | void enable_passthrough(int v); 73 | 74 | const char* loglevnam (int lev); 75 | 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/driver/adc.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADC_H__ 2 | #define __ADC_H__ 3 | 4 | uint16 adc_read(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/driver/dht22.h: -------------------------------------------------------------------------------- 1 | #ifndef __DHT22_H__ 2 | #define __DHT22_H__ 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | #include "user_interface.h" 8 | 9 | typedef enum{ 10 | DHT11 = 0, 11 | DHT22 12 | } DHT_Type; 13 | 14 | #define DHT_MAXTIMINGS 40 15 | #define DHT_READTIMEOUT 250 16 | #define DHT_BREAKTIME 20 17 | 18 | static bool IS_ALREADY_INITED; 19 | 20 | sint16 LAST_DHT_TEMPERATURE; 21 | uint16 LAST_DHT_HUMIDITY; 22 | 23 | bool DHT_Init(uint8 gpiopin, DHT_Type dht_type); 24 | bool DHT_Read(void); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/driver/ds18b20.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_DS18B20_H 2 | #define __I2C_DS18B20_H 3 | 4 | #define DS1820_WRITE_SCRATCHPAD 0x4E 5 | #define DS1820_READ_SCRATCHPAD 0xBE 6 | #define DS1820_COPY_SCRATCHPAD 0x48 7 | #define DS1820_READ_EEPROM 0xB8 8 | #define DS1820_READ_PWRSUPPLY 0xB4 9 | #define DS1820_SEARCHROM 0xF0 10 | #define DS1820_SKIP_ROM 0xCC 11 | #define DS1820_READROM 0x33 12 | #define DS1820_MATCHROM 0x55 13 | #define DS1820_ALARMSEARCH 0xEC 14 | #define DS1820_CONVERT_T 0x44 15 | 16 | // DS18x20 family codes 17 | #define DS18S20 0x10 18 | #define DS18B20 0x28 19 | #endif 20 | -------------------------------------------------------------------------------- /include/driver/gpio16.h: -------------------------------------------------------------------------------- 1 | #ifndef __GPIO16_H__ 2 | #define __GPIO16_H__ 3 | 4 | void gpio16_output_conf(void); 5 | void gpio16_output_set(uint8 value); 6 | void gpio16_input_conf(void); 7 | uint8 gpio16_input_get(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/driver/i2c_at24eep.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_AT24EEP_H 2 | #define __I2C_AT24EEP_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define AT24EEP_ADDRESS 0x50 9 | // may change from 0x50 to 0x57 depend on A0 A1 10 | 11 | static bool IS_ALREADY_INITED = false; 12 | 13 | bool AT24EEP_Init(void); 14 | bool AT24EEP_Read(void); 15 | bool AT24EEP_Write(void); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/driver/i2c_bh1750.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_BH1750_H 2 | #define __I2C_BH1750_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define BH1750_ADDRESS 0x46 //Add Low 9 | //#define BH1750_ADDRESS 0xB8 //Add High 10 | 11 | #define BH1750_CONVERSION_TIME 150 12 | #define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // 1 lx resolution, 120ms 13 | #define BH1750_CONTINUOUS_HIGH_RES_MODE_2 0x11 // 0.5 lx resolution, 120ms 14 | #define BH1750_CONTINUOUS_LOW_RES_MODE 0x13 // 4 lx resolution, 16ms. 15 | #define BH1750_ONE_TIME_HIGH_RES_MODE 0x20 16 | #define BH1750_ONE_TIME_HIGH_RES_MODE_2 0x21 17 | #define BH1750_ONE_TIME_LOW_RES_MODE 0x23 18 | #define BH1750_POWER_DOWN 0x00 // No active state 19 | #define BH1750_POWER_ON 0x01 // Wating for measurment command 20 | #define BH1750_RESET 0x07 // Reset data register value - not accepted in POWER_DOWN mode 21 | 22 | uint16_t LAST_BH_LIGHT; 23 | static bool IS_ALREADY_INITED = false; 24 | 25 | bool BH1750_Init(uint8 mode); 26 | bool BH1750_Read(void); 27 | 28 | #endif -------------------------------------------------------------------------------- /include/driver/i2c_bmp180.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_BMP180_H 2 | #define __I2C_BMP180_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define BMP180_ADDRESS 0xEE 9 | 10 | #define BMP180_CONVERSION_TIME 5 11 | #define BMP180_REG_CHIPID 0xD0 12 | #define BMP180_MAGIC_CHIPID 0x55FF 13 | #define BMP180_MAGIC_CHIPID2 0x5502 14 | #define BMP180_REG_VERSION 0xD1 15 | #define BMP180_REG_CONTROL 0xF4 16 | #define BMP180_REG_RESULT 0xF6 17 | #define BMP180_COMMAND_TEMPERATURE 0x2E // Max conversion time 4.5ms 18 | #define BMP180_COMMAND_PRESSURE0 0x34 // Max conversion time 4.5ms (OSS = 0) 19 | //#define BMP180_COMMAND_PRESSURE1 0x74 // Max conversion time 7.5ms (OSS = 1) 20 | //#define BMP180_COMMAND_PRESSURE2 0xB4 // Max conversion time 13.5ms (OSS = 2) 21 | //#define BMP180_COMMAND_PRESSURE3 0xF4 // Max conversion time 25.5ms (OSS = 3) 22 | 23 | 24 | struct bmp180_inst; 25 | struct bmp180_inst *BMP180_Init(); 26 | bool BMP180_Read(struct bmp180_inst *this); 27 | #endif 28 | -------------------------------------------------------------------------------- /include/driver/i2c_hd44780.h: -------------------------------------------------------------------------------- 1 | #ifndef i2c_hd44780_h 2 | #define i2c_hd44780_h 3 | 4 | #include "ets_sys.h" 5 | #include "osapi.h" 6 | #include "driver/i2c_master.h" 7 | #include "driver/lcd_config.h" 8 | 9 | // commands 10 | #define LCD_CLEARDISPLAY 0x01 11 | #define LCD_RETURNHOME 0x02 12 | #define LCD_ENTRYMODESET 0x04 13 | #define LCD_DISPLAYCONTROL 0x08 14 | #define LCD_CURSORSHIFT 0x10 15 | #define LCD_FUNCTIONSET 0x20 16 | #define LCD_SETCGRAMADDR 0x40 17 | #define LCD_SETDDRAMADDR 0x80 18 | 19 | // flags for display entry mode 20 | #define LCD_ENTRYRIGHT 0x00 21 | #define LCD_ENTRYLEFT 0x02 22 | #define LCD_ENTRYSHIFTINCREMENT 0x01 23 | #define LCD_ENTRYSHIFTDECREMENT 0x00 24 | 25 | // flags for display on/off control 26 | #define LCD_DISPLAYON 0x04 27 | #define LCD_DISPLAYOFF 0x00 28 | #define LCD_CURSORON 0x02 29 | #define LCD_CURSOROFF 0x00 30 | #define LCD_BLINKON 0x01 31 | #define LCD_BLINKOFF 0x00 32 | 33 | // flags for display/cursor shift 34 | #define LCD_DISPLAYMOVE 0x08 35 | #define LCD_CURSORMOVE 0x00 36 | #define LCD_MOVERIGHT 0x04 37 | #define LCD_MOVELEFT 0x00 38 | 39 | // flags for function set 40 | #define LCD_8BITMODE 0x10 41 | #define LCD_4BITMODE 0x00 42 | #define LCD_2LINE 0x08 43 | #define LCD_1LINE 0x00 44 | #define LCD_5x10DOTS 0x04 45 | #define LCD_5x8DOTS 0x00 46 | 47 | // flags for backlight control 48 | #define LCD_BACKLIGHT 0x08 49 | #define LCD_NOBACKLIGHT 0x00 50 | 51 | #define En 0x04 // Enable bit 52 | #define Rw 0x02 // Read/Write bit 53 | #define Rs 0x01 // Register select bit 54 | 55 | void LCD_clear(); 56 | void LCD_home(); 57 | void LCD_noDisplay(); 58 | void LCD_display(); 59 | void LCD_noBlink(); 60 | void LCD_blink(); 61 | void LCD_noCursor(); 62 | void LCD_cursor(); 63 | void LCD_scrollDisplayLeft(); 64 | void LCD_scrollDisplayRight(); 65 | void LCD_printLeft(); 66 | void LCD_printRight(); 67 | void LCD_leftToRight(); 68 | void LCD_rightToLeft(); 69 | void LCD_shiftIncrement(); 70 | void LCD_shiftDecrement(); 71 | void LCD_noBacklight(); 72 | void LCD_backlight(); 73 | void LCD_autoscroll(); 74 | void LCD_noAutoscroll(); 75 | void LCD_createChar(uint8, uint8[]); 76 | void LCD_setCursor(uint8, uint8); 77 | uint8 LCD_init(); 78 | #endif 79 | -------------------------------------------------------------------------------- /include/driver/i2c_hmc5883l.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_HMC5883_H 2 | #define __I2C_HMC5883_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define HMC5883L_ADDRESS 0x3C 9 | //also maybe 1E 3D 10 | 11 | #define HMC5883L_REG_CONFIG_A (0x00) 12 | #define HMC5883L_REG_CONFIG_B (0x01) 13 | #define HMC5883L_REG_MODE (0x02) 14 | #define HMC5883L_REG_OUT_X_M (0x03) 15 | #define HMC5883L_REG_OUT_X_L (0x04) 16 | #define HMC5883L_REG_OUT_Z_M (0x05) 17 | #define HMC5883L_REG_OUT_Z_L (0x06) 18 | #define HMC5883L_REG_OUT_Y_M (0x07) 19 | #define HMC5883L_REG_OUT_Y_L (0x08) 20 | #define HMC5883L_REG_STATUS (0x09) 21 | #define HMC5883L_REG_IDENT_A (0x0A) 22 | #define HMC5883L_REG_IDENT_B (0x0B) 23 | #define HMC5883L_REG_IDENT_C (0x0C) 24 | 25 | #define PI M_PI 26 | #define M_PI 3.14159265358979323846 27 | 28 | typedef enum 29 | { 30 | HMC5883L_SAMPLES_8 = 0b11, 31 | HMC5883L_SAMPLES_4 = 0b10, 32 | HMC5883L_SAMPLES_2 = 0b01, 33 | HMC5883L_SAMPLES_1 = 0b00 34 | } hmc5883l_samples_t; 35 | 36 | typedef enum 37 | { 38 | HMC5883L_DATARATE_75HZ = 0b110, 39 | HMC5883L_DATARATE_30HZ = 0b101, 40 | HMC5883L_DATARATE_15HZ = 0b100, 41 | HMC5883L_DATARATE_7_5HZ = 0b011, 42 | HMC5883L_DATARATE_3HZ = 0b010, 43 | HMC5883L_DATARATE_1_5HZ = 0b001, 44 | HMC5883L_DATARATE_0_75_HZ = 0b000 45 | } hmc5883l_dataRate_t; 46 | 47 | typedef enum 48 | { 49 | HMC5883L_RANGE_8_1GA = 0b111, 50 | HMC5883L_RANGE_5_6GA = 0b110, 51 | HMC5883L_RANGE_4_7GA = 0b101, 52 | HMC5883L_RANGE_4GA = 0b100, 53 | HMC5883L_RANGE_2_5GA = 0b011, 54 | HMC5883L_RANGE_1_9GA = 0b010, 55 | HMC5883L_RANGE_1_3GA = 0b001, 56 | HMC5883L_RANGE_0_88GA = 0b000 57 | } hmc5883l_range_t; 58 | 59 | typedef enum 60 | { 61 | HMC5883L_IDLE = 0b10, 62 | HMC5883L_SINGLE = 0b01, 63 | HMC5883L_CONTINOUS = 0b00 64 | } hmc5883l_mode_t; 65 | 66 | typedef struct 67 | { 68 | sint16 X; 69 | sint16 Y; 70 | sint16 Z; 71 | } Vector; 72 | 73 | Vector LAST_HMC5883_VECTOR; 74 | static bool IS_ALREADY_INITED = false; 75 | 76 | bool HMC5883_Init(void); 77 | bool HMC5883_Read(void); 78 | uint16_t HMC5883_ReadDegrees(); 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/driver/i2c_ina219.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_INA219_H 2 | #define __I2C_INA219_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | //#define INA219_ADDRESS 0x80 9 | #define INA219_ADDRESS 0x82 10 | 11 | #define INA219_REG_CONFIG 0x00 12 | #define INA219_REG_SHUNTVOLTAGE 0x01 13 | #define INA219_REG_BUSVOLTAGE 0x02 14 | #define INA219_REG_POWER 0x03 15 | #define INA219_REG_CURRENT 0x04 16 | #define INA219_REG_CALIBRATION 0x05 17 | 18 | typedef enum 19 | { 20 | INA219_RANGE_16V = 0b0, 21 | INA219_RANGE_32V = 0b1 22 | } ina219_range_t; 23 | 24 | typedef enum 25 | { 26 | INA219_GAIN_40MV = 0b00, 27 | INA219_GAIN_80MV = 0b01, 28 | INA219_GAIN_160MV = 0b10, 29 | INA219_GAIN_320MV = 0b11 30 | } ina219_gain_t; 31 | 32 | typedef enum 33 | { 34 | INA219_BUS_RES_9BIT = 0b0000, 35 | INA219_BUS_RES_10BIT = 0b0001, 36 | INA219_BUS_RES_11BIT = 0b0010, 37 | INA219_BUS_RES_12BIT = 0b0011 38 | } ina219_busRes_t; 39 | 40 | typedef enum 41 | { 42 | INA219_SHUNT_RES_9BIT_1S = 0b0000, 43 | INA219_SHUNT_RES_10BIT_1S = 0b0001, 44 | INA219_SHUNT_RES_11BIT_1S = 0b0010, 45 | INA219_SHUNT_RES_12BIT_1S = 0b0011, 46 | INA219_SHUNT_RES_12BIT_2S = 0b1001, 47 | INA219_SHUNT_RES_12BIT_4S = 0b1010, 48 | INA219_SHUNT_RES_12BIT_8S = 0b1011, 49 | INA219_SHUNT_RES_12BIT_16S = 0b1100, 50 | INA219_SHUNT_RES_12BIT_32S = 0b1101, 51 | INA219_SHUNT_RES_12BIT_64S = 0b1110, 52 | INA219_SHUNT_RES_12BIT_128S = 0b1111 53 | } ina219_shuntRes_t; 54 | 55 | typedef enum 56 | { 57 | INA219_MODE_POWER_DOWN = 0b000, 58 | INA219_MODE_SHUNT_TRIG = 0b001, 59 | INA219_MODE_BUS_TRIG = 0b010, 60 | INA219_MODE_SHUNT_BUS_TRIG = 0b011, 61 | INA219_MODE_ADC_OFF = 0b100, 62 | INA219_MODE_SHUNT_CONT = 0b101, 63 | INA219_MODE_BUS_CONT = 0b110, 64 | INA219_MODE_SHUNT_BUS_CONT = 0b111, 65 | } ina219_mode_t; 66 | 67 | enum { 68 | CONFIGURE_READ_POWERDOWN = 0, 69 | GET_VOLTAGE, 70 | GET_CURRENT, 71 | GET_SHUNT_VOLTAGE, 72 | GET_POWER 73 | }; 74 | 75 | #define INA219_CALIBRATION_VALUE 4096 //RSHUNT = 0.1 ohm; max expected I = 1 A 76 | #define INA219_CONFIG_VALUE (INA219_RANGE_16V << 13 | INA219_GAIN_80MV << 11 | INA219_BUS_RES_12BIT << 7 | INA219_SHUNT_RES_12BIT_1S << 3) 77 | 78 | uint16 LAST_INA219_VOLTAGE; 79 | uint16 LAST_INA219_CURRENT; 80 | uint16 LAST_INA219_SHUNT_VOLTAGE; 81 | uint16 LAST_INA219_POWER; 82 | static bool IS_ALREADY_INITED; 83 | 84 | bool INA219_Init(void); 85 | bool INA219_Read(void); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /include/driver/i2c_master.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_MASTER_H__ 2 | #define __I2C_MASTER_H__ 3 | 4 | #include "os_type.h" 5 | #include "user_interface.h" 6 | 7 | #define I2C_SLEEP_TIME 5 8 | 9 | bool i2c_master_gpio_init(uint8 sda, uint8 scl); 10 | void i2c_master_init(void); 11 | 12 | #define i2c_master_wait os_delay_us 13 | void i2c_master_stop(void); 14 | void i2c_master_start(void); 15 | void i2c_master_setAck(uint8 level); 16 | uint8 i2c_master_getAck(void); 17 | uint8 i2c_master_readByte(void); 18 | void i2c_master_writeByte(uint8 wrdata); 19 | 20 | //TODO: bool i2c_master_writeBytes(uint8 address, uint8 value, ...); 21 | bool i2c_master_writeBytes(uint8 address, uint8 *values, uint8 length); 22 | bool i2c_master_writeBytes1(uint8 address, uint8 byte1); 23 | bool i2c_master_writeBytes2(uint8 address, uint8 byte1, uint8 byte2); 24 | bool i2c_master_writeBytes3(uint8 address, uint8 byte1, uint8 byte2, uint8 byte3); 25 | bool i2c_master_readBytes(uint8 address, uint8 *values, uint8 length); 26 | bool i2c_master_readUint8(uint8 address, uint8 regaddr, uint8 *value); 27 | bool i2c_master_readUint16(uint8 address, uint8 regaddr, uint16 *value); 28 | bool i2c_master_readSint16(uint8 address, uint8 regaddr, sint16 *value); 29 | 30 | bool i2c_master_checkAck(void); 31 | void i2c_master_send_ack(void); 32 | void i2c_master_send_nack(void); 33 | 34 | uint8 i2c_master_get_pinSDA(); 35 | uint8 i2c_master_get_pinSCL(); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/driver/i2c_mlx90614.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_MLX90614_H 2 | #define __I2C_MLX90614_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define MLX90614_ADDRESS 0xB4 9 | 10 | #define MLX90614_RAWIR1 0x04 11 | #define MLX90614_RAWIR2 0x05 12 | #define MLX90614_TA 0x06 13 | #define MLX90614_TOBJ1 0x07 14 | #define MLX90614_TOBJ2 0x08 15 | 16 | #define MLX90614_TOMAX 0x20 17 | #define MLX90614_TOMIN 0x21 18 | #define MLX90614_PWMCTRL 0x22 19 | #define MLX90614_TARANGE 0x23 20 | #define MLX90614_EMISS 0x24 21 | #define MLX90614_CONFIG 0x25 22 | 23 | #define MLX90614_ID1 0x3C 24 | #define MLX90614_ID2 0x3D 25 | #define MLX90614_ID3 0x3E 26 | #define MLX90614_ID4 0x3F 27 | 28 | #ifdef CONFIG_USEFLOAT 29 | float LAST_MLX90614_AMBIENT_TEMPERATURE; 30 | float LAST_MLX90614_OBJECT_TEMPERATURE; 31 | #else 32 | sint16 LAST_MLX90614_AMBIENT_TEMPERATURE; 33 | sint16 LAST_MLX90614_OBJECT_TEMPERATURE; 34 | #endif 35 | static bool IS_ALREADY_INITED = false; 36 | 37 | bool MLX90614_Init(void); 38 | bool MLX90614_Read(void); 39 | 40 | #endif -------------------------------------------------------------------------------- /include/driver/i2c_pcf8591.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_PCF8591_H 2 | #define __I2C_PCF8591_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define PCF8591_ADDRESS 0x90 9 | 10 | #define PCF8591_REG_READ_ALL 0x04 11 | #define PCF8591_REG_DAC 0x40 12 | 13 | uint8 LAST_PCF8591_A[4]; 14 | static bool IS_ALREADY_INITED = false; 15 | 16 | bool PCF8591_Init(void); 17 | bool PCF8591_Read(void); 18 | bool PCF8591_Write(uint8_t value); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/driver/i2c_sht21.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_SHT21_H 2 | #define __I2C_SHT21_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define SHT21_ADDRESS 0x80 9 | 10 | #define SHT21_CONVERSION_TIME 30 11 | #define SHT21_SOFT_RESET_TIME 15 12 | 13 | #define SHT21_TRIGGER_TEMP_MEASURE_HOLD 0xE3 14 | #define SHT21_TRIGGER_HUMD_MEASURE_HOLD 0xE5 15 | #define SHT21_TRIGGER_TEMP_MEASURE_NOHOLD 0xF3 16 | #define SHT21_TRIGGER_HUMD_MEASURE_NOHOLD 0xF5 17 | #define SHT21_WRITE_USER_REG 0xE6 18 | #define SHT21_READ_USER_REG 0xE7 19 | #define SHT21_SOFT_RESET 0xFE 20 | 21 | #ifdef CONFIG_USEFLOAT 22 | float LAST_SHT_TEMPERATURE; 23 | float LAST_SHT_HUMIDITY; 24 | #else 25 | int32 LAST_SHT_TEMPERATURE; 26 | uint16 LAST_SHT_HUMIDITY; 27 | #endif 28 | static bool IS_ALREADY_INITED = false; 29 | 30 | bool SHT21_Init(void); 31 | bool SHT21_Read(void); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/driver/i2c_si7020.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_SI7020_H 2 | #define __I2C_SI7020_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define SI7020_RESET (0xfe) 9 | #define SI7020_ADDRESS (0x80) 10 | #define SI7020_HUMIDITY (0xe5) 11 | /* 12 | * 0xe0 re-uses the measurement made during the humidity measurement 13 | * 0xe3 is a real temperature measurement. 14 | */ 15 | #define SI7020_TEMPERATURE_STORED (0xe0) 16 | #define SI7020_TEMPERATURE (0xe3) 17 | 18 | bool SI7020_Init(void); 19 | bool SI7020_Read_Temperature(uint16_t *); 20 | bool SI7020_Read_Humidity(uint16_t *); 21 | 22 | static bool IS_ALREADY_INITED = false; 23 | #endif 24 | -------------------------------------------------------------------------------- /include/driver/i2c_tcs3414cs.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_TCS3414_H 2 | #define __I2C_TCS3414_H 3 | 4 | #include "c_types.h" 5 | #include "ets_sys.h" 6 | #include "osapi.h" 7 | 8 | #define TCS3414_ADDRESS 0x72 9 | //also address maybe 52 or 92 10 | 11 | #define TCS3414_REG_CTL 0x80 12 | #define TCS3414_REG_TIMING 0x81 13 | #define TCS3414_REG_INT 0x82 14 | #define TCS3414_REG_INT_SOURCE 0x83 15 | #define TCS3414_REG_ID 0x84 16 | #define TCS3414_REG_GAIN 0x87 17 | #define TCS3414_REG_LOW_THRESH_LOW_BYTE 0x88 18 | #define TCS3414_REG_LOW_THRESH_HIGH_BYTE 0x89 19 | #define TCS3414_REG_HIGH_THRESH_LOW_BYTE 0x8A 20 | #define TCS3414_REG_HIGH_THRESH_HIGH_BYTE 0x8B 21 | #define TCS3414_REG_BLOCK_READ 0xCF 22 | #define TCS3414_REG_GREEN_LOW 0xD0 23 | #define TCS3414_REG_GREEN_HIGH 0xD1 24 | #define TCS3414_REG_RED_LOW 0xD2 25 | #define TCS3414_REG_RED_HIGH 0xD3 26 | #define TCS3414_REG_BLUE_LOW 0xD4 27 | #define TCS3414_REG_BLUE_HIGH 0xD5 28 | #define TCS3414_REG_CLEAR_LOW 0xD6 29 | #define TCS3414_REG_CLEAR_HIGH 0xD7 30 | #define TCS3414_CTL_DAT_INIITIATE 0x03 31 | #define TCS3414_CLR_INT 0xE0 32 | 33 | //Timing Register 34 | #define TCS3414_SYNC_EDGE 0x40 35 | #define TCS3414_INTEG_MODE_FREE 0x00 36 | #define TCS3414_INTEG_MODE_MANUAL 0x10 37 | #define TCS3414_INTEG_MODE_SYN_SINGLE 0x20 38 | #define TCS3414_INTEG_MODE_SYN_MULTI 0x30 39 | 40 | #define TCS3414_INTEGRATION_TIME_12ms 0x00 41 | #define TCS3414_INTEGRATION_TIME_100ms 0x01 42 | #define TCS3414_INTEGRATION_TIME_400ms 0x02 43 | 44 | #define TCS3414_INTEG_PARAM_PULSE_COUNT1 0x00 45 | #define TCS3414_INTEG_PARAM_PULSE_COUNT2 0x01 46 | #define TCS3414_INTEG_PARAM_PULSE_COUNT4 0x02 47 | #define TCS3414_INTEG_PARAM_PULSE_COUNT8 0x03 48 | 49 | //Interrupt Control Register 50 | #define TCS3414_INTR_STOP 40 51 | #define TCS3414_INTR_DISABLE 0x00 52 | #define TCS3414_INTR_LEVEL 0x10 53 | #define TCS3414_INTR_PERSIST_EVERY 0x00 54 | #define TCS3414_INTR_PERSIST_SINGLE 0x01 55 | 56 | //Interrupt Souce Register 57 | #define TCS3414_INT_SOURCE_GREEN 0x00 58 | #define TCS3414_INT_SOURCE_RED 0x01 59 | #define TCS3414_INT_SOURCE_BLUE 0x10 60 | #define TCS3414_INT_SOURCE_CLEAR 0x03 61 | 62 | //Gain Register 63 | #define TCS3414_GAIN_1 0x00 64 | #define TCS3414_GAIN_4 0x10 65 | #define TCS3414_GAIN_16 0x20 66 | #define TCS3414_GANI_64 0x30 67 | #define TCS3414_PRESCALER_1 0x00 68 | #define TCS3414_PRESCALER_2 0x01 69 | #define TCS3414_PRESCALER_4 0x02 70 | #define TCS3414_PRESCALER_8 0x03 71 | #define TCS3414_PRESCALER_16 0x04 72 | #define TCS3414_PRESCALER_32 0x05 73 | #define TCS3414_PRESCALER_64 0x06 74 | 75 | typedef struct 76 | { 77 | uint32_t R; 78 | uint32_t G; 79 | uint32_t B; 80 | uint32_t W; 81 | } Color; 82 | 83 | Color LAST_TCS3414_COLOR; 84 | static bool IS_ALREADY_INITED = false; 85 | 86 | bool TCS3414_Init(void); 87 | bool TCS3414_SetTimeing(uint8_t timeing, uint8_t gain); 88 | bool TCS3414_SetInterrupt(uint8_t interruptSource, uint8_t interruptControl); 89 | bool TCS3414_Read(void); 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /include/driver/key.h: -------------------------------------------------------------------------------- 1 | #ifndef __KEY_H__ 2 | #define __KEY_H__ 3 | 4 | #include "gpio.h" 5 | 6 | typedef void (* key_function)(void); 7 | 8 | struct single_key_param { 9 | uint8 key_level; 10 | uint8 gpio_id; 11 | uint8 gpio_func; 12 | uint32 gpio_name; 13 | os_timer_t key_5s; 14 | os_timer_t key_50ms; 15 | key_function short_press; 16 | key_function long_press; 17 | }; 18 | 19 | struct keys_param { 20 | uint8 key_num; 21 | struct single_key_param **single_key; 22 | }; 23 | 24 | struct single_key_param *key_init_single(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func, key_function long_press, key_function short_press); 25 | void key_init(struct keys_param *key); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/driver/lcd_config.h: -------------------------------------------------------------------------------- 1 | #define LCD_COL 20 2 | #define LCD_ROW 4 3 | #define LCD_DOTSIZE 0 4 | #define LCD_ADDRESS 0x27 5 | -------------------------------------------------------------------------------- /include/driver/pwm.h: -------------------------------------------------------------------------------- 1 | #ifndef __PWM_H__ 2 | #define __PWM_H__ 3 | 4 | #define PWM_CHANNEL 3 5 | 6 | struct pwm_single_param { 7 | uint16 gpio_set; 8 | uint16 gpio_clear; 9 | uint16 h_time; 10 | }; 11 | 12 | struct pwm_param { 13 | uint16 period; 14 | uint16 freq; 15 | uint8 duty[PWM_CHANNEL]; 16 | }; 17 | 18 | #define PWM_DEPTH 255 19 | 20 | #define PWM_1S 1000000 21 | 22 | #define PWM_0_OUT_IO_MUX PERIPHS_IO_MUX_MTDI_U 23 | #define PWM_0_OUT_IO_NUM 12 24 | #define PWM_0_OUT_IO_FUNC FUNC_GPIO12 25 | 26 | #define PWM_1_OUT_IO_MUX PERIPHS_IO_MUX_MTDO_U 27 | #define PWM_1_OUT_IO_NUM 15 28 | #define PWM_1_OUT_IO_FUNC FUNC_GPIO15 29 | 30 | #define PWM_2_OUT_IO_MUX PERIPHS_IO_MUX_MTCK_U 31 | #define PWM_2_OUT_IO_NUM 13 32 | #define PWM_2_OUT_IO_FUNC FUNC_GPIO13 33 | 34 | void pwm_init(uint16 freq, uint8 *duty); 35 | void pwm_start(void); 36 | 37 | void pwm_set_duty(uint8 duty, uint8 channel); 38 | uint8 pwm_get_duty(uint8 channel); 39 | void pwm_set_freq(uint16 freq); 40 | uint16 pwm_get_freq(void); 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /include/driver/spi_master.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPI_MASTER_H__ 2 | #define __SPI_MASTER_H__ 3 | 4 | #include "driver/spi_register.h" 5 | 6 | /*SPI number define*/ 7 | #define SPI 0 8 | #define HSPI 1 9 | 10 | void spi_master_init(uint8 spi_no); 11 | void spi_master_9bit_write(uint8 spi_no, uint8 high_bit, uint8 low_8bit); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /include/driver/uart.h: -------------------------------------------------------------------------------- 1 | #ifndef UART_APP_H 2 | #define UART_APP_H 3 | 4 | #include "uart_register.h" 5 | 6 | #define RX_BUFF_SIZE 0x100 7 | #define TX_BUFF_SIZE 100 8 | 9 | typedef enum { 10 | FIVE_BITS = 0x0, 11 | SIX_BITS = 0x1, 12 | SEVEN_BITS = 0x2, 13 | EIGHT_BITS = 0x3 14 | } UartBitsNum4Char; 15 | 16 | typedef enum { 17 | ONE_STOP_BIT = 0, 18 | ONE_HALF_STOP_BIT = BIT2, 19 | TWO_STOP_BIT = BIT2 20 | } UartStopBitsNum; 21 | 22 | typedef enum { 23 | NONE_BITS = 0, 24 | ODD_BITS = 0, 25 | EVEN_BITS = BIT4 26 | } UartParityMode; 27 | 28 | typedef enum { 29 | STICK_PARITY_DIS = 0, 30 | STICK_PARITY_EN = BIT3 | BIT5 31 | } UartExistParity; 32 | 33 | typedef enum { 34 | BIT_RATE_9600 = 9600, 35 | BIT_RATE_19200 = 19200, 36 | BIT_RATE_38400 = 38400, 37 | BIT_RATE_57600 = 57600, 38 | BIT_RATE_74880 = 74880, 39 | BIT_RATE_115200 = 115200, 40 | BIT_RATE_230400 = 230400, 41 | BIT_RATE_460800 = 460800, 42 | BIT_RATE_921600 = 921600 43 | } UartBautRate; 44 | 45 | typedef enum { 46 | NONE_CTRL, 47 | HARDWARE_CTRL, 48 | XON_XOFF_CTRL 49 | } UartFlowCtrl; 50 | 51 | typedef enum { 52 | EMPTY, 53 | UNDER_WRITE, 54 | WRITE_OVER 55 | } RcvMsgBuffState; 56 | 57 | typedef struct { 58 | uint32 RcvBuffSize; 59 | uint8 *pRcvMsgBuff; 60 | uint8 *pWritePos; 61 | uint8 *pReadPos; 62 | uint8 TrigLvl; //JLU: may need to pad 63 | RcvMsgBuffState BuffState; 64 | } RcvMsgBuff; 65 | 66 | typedef struct { 67 | uint32 TrxBuffSize; 68 | uint8 *pTrxBuff; 69 | } TrxMsgBuff; 70 | 71 | typedef enum { 72 | BAUD_RATE_DET, 73 | WAIT_SYNC_FRM, 74 | SRCH_MSG_HEAD, 75 | RCV_MSG_BODY, 76 | RCV_ESC_CHAR, 77 | } RcvMsgState; 78 | 79 | typedef struct { 80 | UartBautRate baut_rate; 81 | UartBitsNum4Char data_bits; 82 | UartExistParity exist_parity; 83 | UartParityMode parity; // chip size in byte 84 | UartStopBitsNum stop_bits; 85 | UartFlowCtrl flow_ctrl; 86 | RcvMsgBuff rcv_buff; 87 | TrxMsgBuff trx_buff; 88 | RcvMsgState rcv_state; 89 | int received; 90 | int buff_uart_no; //indicate which uart use tx/rx buffer 91 | } UartDevice; 92 | 93 | void uart_init(int port, UartBautRate br); 94 | void uart_init_io(); 95 | 96 | 97 | #endif 98 | 99 | -------------------------------------------------------------------------------- /include/env.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENV_H_ 3 | #define _ENV_H_ 4 | 5 | void env_init(uint32_t flashaddr, uint32_t envsize); 6 | int env_insert(const char* key, const char *value); 7 | const char* env_get(const char* key); 8 | void env_save(void); 9 | void env_dump(void); 10 | void env_reset(void); 11 | int env_delete(const char* key); 12 | 13 | #endif // _ENV_H_ 14 | -------------------------------------------------------------------------------- /include/espmissingincludes.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPMISSINGINCLUDES_H 2 | #define ESPMISSINGINCLUDES_H 3 | 4 | #include 5 | #include 6 | 7 | //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. 8 | //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. 9 | typedef struct espconn espconn; 10 | 11 | int atoi(const char *nptr); 12 | void ets_install_putc1(void *routine); 13 | void ets_isr_attach(int intr, void *handler, void *arg); 14 | void ets_isr_mask(unsigned intr); 15 | void ets_isr_unmask(unsigned intr); 16 | int ets_memcmp(const void *s1, const void *s2, size_t n); 17 | void *ets_memcpy(void *dest, const void *src, size_t n); 18 | void *ets_memset(void *s, int c, size_t n); 19 | int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); 20 | int ets_str2macaddr(void *, void *); 21 | int ets_strcmp(const char *s1, const char *s2); 22 | char *ets_strcpy(char *dest, const char *src); 23 | size_t ets_strlen(const char *s); 24 | int ets_strncmp(const char *s1, const char *s2, int len); 25 | char *ets_strncpy(char *dest, const char *src, size_t n); 26 | char *ets_strstr(const char *haystack, const char *needle); 27 | void ets_timer_arm_new(ETSTimer *a, int b, int c, int isMstimer); 28 | void ets_timer_disarm(ETSTimer *a); 29 | void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *fn, void *parg); 30 | void ets_update_cpu_frequency(int freqmhz); 31 | int ets_uart_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 32 | int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 33 | 34 | int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4))); 35 | int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 36 | void uart_div_modify(int no, unsigned int freq); 37 | uint8 wifi_get_opmode(void); 38 | uint32 system_get_time(); 39 | int rand(void); 40 | void ets_bzero(void *s, size_t n); 41 | void ets_delay_us(int ms); 42 | #endif 43 | -------------------------------------------------------------------------------- /include/flash_layout.h: -------------------------------------------------------------------------------- 1 | #ifndef FLASH_LAYOUT_H 2 | #define FLASH_LAYOUT_H 3 | 4 | uint32_t fr_get_firmware_size(); 5 | uint32_t fr_fs_flash_offset(); 6 | void *fr_fs_physaddr(); 7 | uint32_t fr_fs_size(); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /include/generic/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACRO_H 2 | #define __MACRO_H 3 | 4 | /* Borrowed from the linux kernel. Don't try to understand it. */ 5 | 6 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 7 | 8 | #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) 9 | 10 | #ifndef CONFIG_TOOLCHAIN_SDCC 11 | #define min_t(type, x, y) ({ \ 12 | type __min1 = (x); \ 13 | type __min2 = (y); \ 14 | __min1 < __min2 ? __min1: __min2; }) 15 | 16 | 17 | #define max_t(type, x, y) ({ \ 18 | type __max1 = (x); \ 19 | type __max2 = (y); \ 20 | __max1 > __max2 ? __max1: __max2; }) 21 | 22 | #else 23 | 24 | 25 | #define min_t(type, a, b) (((type)(a)<(type)(b))?(type)(a):(type)(b)) 26 | #define max_t(type, a, b) (((type)(a)>(type)(b))?(type)(a):(type)(b)) 27 | 28 | #endif 29 | 30 | /* Just in case */ 31 | #ifndef NULL 32 | #define NULL 0 33 | #endif 34 | 35 | /* Macro concatenation magic. 36 | * Stolen from somewhere on the internets 37 | */ 38 | 39 | /* 40 | * Concatenate preprocessor tokens A and B without expanding macro definitions 41 | * (however, if invoked from a macro, macro arguments are expanded). 42 | */ 43 | #define PPCAT_NX(A, B) A ## B 44 | 45 | /* 46 | * Concatenate preprocessor tokens A and B without expanding macro definitions 47 | * (however, if invoked from a macro, macro arguments are expanded). 48 | */ 49 | #define PPCAT_NX3(A, B, C) A ## B ## C 50 | 51 | /* 52 | * Concatenate preprocessor tokens A and B after macro-expanding them. 53 | */ 54 | #define PPCAT(A, B) PPCAT_NX(A, B) 55 | 56 | /* 57 | * Concatenate preprocessor tokens A and B after macro-expanding them. 58 | */ 59 | #define PPCAT3(A, B, C) PPCAT_NX3(A, B, C) 60 | 61 | 62 | #define QUOTE(str) #str 63 | #define EXPAND_AND_QUOTE(str) QUOTE(str) 64 | 65 | /* 66 | * Macrofied, so that we can later add implementations 67 | * for compilers that don't know about 0b prefix 68 | * So far both gcc and sdcc can do this stuff 69 | */ 70 | 71 | #define BIN(x) 0b##x 72 | 73 | #ifndef _BV 74 | #define _BV(a) (1<" 5 | #define HEATSHRINK_URL "https://github.com/atomicobject/heatshrink" 6 | 7 | /* Version 0.3.1 */ 8 | #define HEATSHRINK_VERSION_MAJOR 0 9 | #define HEATSHRINK_VERSION_MINOR 3 10 | #define HEATSHRINK_VERSION_PATCH 1 11 | 12 | #define HEATSHRINK_MIN_WINDOW_BITS 4 13 | #define HEATSHRINK_MAX_WINDOW_BITS 15 14 | 15 | #define HEATSHRINK_MIN_LOOKAHEAD_BITS 2 16 | 17 | #define HEATSHRINK_LITERAL_MARKER 0x01 18 | #define HEATSHRINK_BACKREF_MARKER 0x00 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/heatshrink_config.h: -------------------------------------------------------------------------------- 1 | #ifndef HEATSHRINK_CONFIG_H 2 | #define HEATSHRINK_CONFIG_H 3 | 4 | /* Should functionality assuming dynamic allocation be used? */ 5 | #define HEATSHRINK_DYNAMIC_ALLOC 1 6 | 7 | #if HEATSHRINK_DYNAMIC_ALLOC 8 | /* Optional replacement of malloc/free */ 9 | #define HEATSHRINK_MALLOC(SZ) malloc(SZ) 10 | #define HEATSHRINK_FREE(P, SZ) free(P) 11 | #else 12 | /* Required parameters for static configuration */ 13 | #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 14 | #define HEATSHRINK_STATIC_WINDOW_BITS 8 15 | #define HEATSHRINK_STATIC_LOOKAHEAD_BITS 4 16 | #endif 17 | 18 | /* Turn on logging for debugging. */ 19 | #define HEATSHRINK_DEBUGGING_LOGS 0 20 | 21 | /* Use indexing for faster compression. (This requires additional space.) */ 22 | #define HEATSHRINK_USE_INDEX 1 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef HELPERS_H 2 | #define HELPERS_H 3 | 4 | 5 | /* boilerplate for copypaste: 6 | * Don't wrap in macro - will screw up doxygen 7 | 8 | const char ICACHE_FLASH_ATTR *id_to_(int id); 9 | int ICACHE_FLASH_ATTR id_from_(const char *id); 10 | 11 | */ 12 | 13 | const char ICACHE_FLASH_ATTR *id_to_wireless_mode(int id); 14 | int ICACHE_FLASH_ATTR id_from_wireless_mode(const char *id); 15 | 16 | const char ICACHE_FLASH_ATTR *id_to_encryption_mode(int id); 17 | int ICACHE_FLASH_ATTR id_from_encryption_mode(const char *id); 18 | 19 | const char ICACHE_FLASH_ATTR *id_to_iface_name(int id); 20 | int ICACHE_FLASH_ATTR id_from_iface_name(const char *id); 21 | 22 | const char ICACHE_FLASH_ATTR *id_to_iface_description(int id); 23 | int ICACHE_FLASH_ATTR id_from_iface_description(const char *id); 24 | 25 | const char ICACHE_FLASH_ATTR *id_to_sta_state(int id); 26 | int ICACHE_FLASH_ATTR id_from_sta_state(const char *id); 27 | 28 | unsigned long skip_atoul(const char **s); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/hostname.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _HOSTNAME_H 3 | #define _HOSTNAME_H 4 | 5 | void set_dhcp_hostname(char *hname); 6 | 7 | #endif // _HOSTNAME_H 8 | -------------------------------------------------------------------------------- /include/httpdconfig.h: -------------------------------------------------------------------------------- 1 | 2 | //Define this if you want to be able to use Heatshrink-compressed espfs images. 3 | #define EFS_HEATSHRINK 4 | 5 | //If you want, you can define a realm for the authentication system. 6 | #define HTTP_AUTH_REALM "Realm Of Shameless Bloat" 7 | -------------------------------------------------------------------------------- /include/iwconnect.h: -------------------------------------------------------------------------------- 1 | #ifndef IW_H__ 2 | #define IW_H__ 3 | 4 | extern int exec_iwconnect(const char *ssid, const char *password); 5 | 6 | #endif 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /include/lib/config.h: -------------------------------------------------------------------------------- 1 | /* config.h 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef USER_CONFIG_H_ 32 | #define USER_CONFIG_H_ 33 | #include "os_type.h" 34 | #include 35 | typedef struct{ 36 | uint8_t device_id[16]; 37 | uint8_t mqtt_host[64]; 38 | uint32_t mqtt_port; 39 | uint8_t mqtt_user[32]; 40 | uint8_t mqtt_pass[32]; 41 | uint32_t mqtt_keepalive; 42 | uint8_t security; 43 | } SYSCFG; 44 | 45 | typedef struct { 46 | uint8 flag; 47 | uint8 pad[3]; 48 | } SAVE_FLAG; 49 | 50 | void ICACHE_FLASH_ATTR CFG_Save(); 51 | void ICACHE_FLASH_ATTR CFG_Load(); 52 | 53 | extern SYSCFG sysCfg; 54 | 55 | #endif /* USER_CONFIG_H_ */ 56 | -------------------------------------------------------------------------------- /include/lib/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: Dec 4, 2014 5 | * Author: Minh 6 | */ 7 | 8 | #ifndef USER_DEBUG_H_ 9 | #define USER_DEBUG_H_ 10 | 11 | #ifndef INFO 12 | #define INFO os_printf 13 | #endif 14 | 15 | #endif /* USER_DEBUG_H_ */ 16 | -------------------------------------------------------------------------------- /include/lib/proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: proto.h 3 | * Author: ThuHien 4 | * 5 | * Created on November 23, 2012, 8:57 AM 6 | */ 7 | 8 | #ifndef _PROTO_H_ 9 | #define _PROTO_H_ 10 | #include 11 | #include "typedef.h" 12 | #include "ringbuf.h" 13 | 14 | typedef void(PROTO_PARSE_CALLBACK)(); 15 | 16 | typedef struct{ 17 | U8 *buf; 18 | U16 bufSize; 19 | U16 dataLen; 20 | U8 isEsc; 21 | U8 isBegin; 22 | PROTO_PARSE_CALLBACK* callback; 23 | }PROTO_PARSER; 24 | 25 | I8 ICACHE_FLASH_ATTR PROTO_Init(PROTO_PARSER *parser, PROTO_PARSE_CALLBACK *completeCallback, U8 *buf, U16 bufSize); 26 | I8 ICACHE_FLASH_ATTR PROTO_Parse(PROTO_PARSER *parser, U8 *buf, U16 len); 27 | I16 ICACHE_FLASH_ATTR PROTO_Add(U8 *buf, const U8 *packet, I16 bufSize); 28 | I16 ICACHE_FLASH_ATTR PROTO_AddRb(RINGBUF *rb, const U8 *packet, I16 len); 29 | I8 ICACHE_FLASH_ATTR PROTO_ParseByte(PROTO_PARSER *parser, U8 value); 30 | I16 ICACHE_FLASH_ATTR PROTO_ParseRb(RINGBUF *rb, U8 *bufOut, U16* len, U16 maxBufLen); 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /include/lib/queue.h: -------------------------------------------------------------------------------- 1 | /* str_queue.h -- 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef USER_QUEUE_H_ 32 | #define USER_QUEUE_H_ 33 | #include "os_type.h" 34 | #include "ringbuf.h" 35 | typedef struct { 36 | uint8_t *buf; 37 | RINGBUF rb; 38 | } QUEUE; 39 | 40 | void ICACHE_FLASH_ATTR QUEUE_Init(QUEUE *queue, int bufferSize); 41 | int32_t ICACHE_FLASH_ATTR QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len); 42 | int32_t ICACHE_FLASH_ATTR QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen); 43 | BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty(QUEUE *queue); 44 | #endif /* USER_QUEUE_H_ */ 45 | -------------------------------------------------------------------------------- /include/lib/ringbuf.h: -------------------------------------------------------------------------------- 1 | #ifndef _RING_BUF_H_ 2 | #define _RING_BUF_H_ 3 | 4 | #include 5 | #include 6 | #include "typedef.h" 7 | 8 | typedef struct{ 9 | U8* p_o; /**< Original pointer */ 10 | U8* volatile p_r; /**< Read pointer */ 11 | U8* volatile p_w; /**< Write pointer */ 12 | volatile I32 fill_cnt; /**< Number of filled slots */ 13 | I32 size; /**< Buffer size */ 14 | }RINGBUF; 15 | 16 | I16 ICACHE_FLASH_ATTR RINGBUF_Init(RINGBUF *r, U8* buf, I32 size); 17 | I16 ICACHE_FLASH_ATTR RINGBUF_Put(RINGBUF *r, U8 c); 18 | I16 ICACHE_FLASH_ATTR RINGBUF_Get(RINGBUF *r, U8* c); 19 | #endif 20 | -------------------------------------------------------------------------------- /include/lib/tftp.h: -------------------------------------------------------------------------------- 1 | #ifndef LIB_TFTP_H 2 | #define LIB_TFTP_H 3 | 4 | 5 | struct tftp_server { 6 | int pos; 7 | int port; 8 | struct udp_pcb *out; 9 | struct ip_addr addr; 10 | uint16_t pblen; 11 | int numblock; 12 | void (*recv)(struct tftp_server *ts, int num_block, char* buf, int len); 13 | void (*err)(struct tftp_server *ts, int errcode, char* text); 14 | void *userdata; 15 | }; 16 | 17 | err_t tftp_start(struct tftp_server *ts, struct ip_addr *addr, int port); 18 | void tftp_stop(struct tftp_server *ts); 19 | 20 | void tftp_recv(struct tftp_server *ts, 21 | void (*recv)(struct tftp_server *ts, int num_block, char* buf, int len)); 22 | 23 | void tftp_err(struct tftp_server *ts, 24 | void (*err)(struct tftp_server *ts, int errcode, char* text)); 25 | 26 | void tftp_request(struct tftp_server *ts, const char* host, const char* dir, const char *fname); 27 | 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /include/lib/typedef.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Standard Types definition 4 | */ 5 | 6 | #ifndef _TYPE_DEF_H_ 7 | #define _TYPE_DEF_H_ 8 | 9 | typedef char I8; 10 | typedef unsigned char U8; 11 | typedef short I16; 12 | typedef unsigned short U16; 13 | typedef long I32; 14 | typedef unsigned long U32; 15 | typedef unsigned long long U64; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /include/lib/user_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _USER_CONFIG_H_ 2 | #define _USER_CONFIG_H_ 3 | 4 | #define CFG_HOLDER 0x00FF55A4 /* Change this value to load default configurations */ 5 | #define CFG_LOCATION 0x3C /* Please don't change or if you know what you doing */ 6 | #define CLIENT_SSL_ENABLE 7 | 8 | /*DEFAULT CONFIGURATIONS*/ 9 | 10 | #define MQTT_HOST "192.168.0.101" //or "mqtt.yourdomain.com" 11 | /*#define MQTT_PORT 1880 */ 12 | #define MQTT_PORT 1883 13 | #define MQTT_BUF_SIZE 1024 14 | #define MQTT_KEEPALIVE 120 /*second*/ 15 | 16 | #define MQTT_CLIENT_ID "DVES_%08X" 17 | #define MQTT_USER "" 18 | #define MQTT_PASS "" 19 | 20 | #define MQTT_RECONNECT_TIMEOUT 5 /*second*/ 21 | 22 | #define DEFAULT_SECURITY 0 23 | #define QUEUE_BUFFER_SIZE 2048 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/lib/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | #include "c_types.h" 5 | 6 | uint32_t ICACHE_FLASH_ATTR UTILS_Atoh(const int8_t *s); 7 | uint8_t ICACHE_FLASH_ATTR UTILS_StrToIP(const int8_t* str, void *ip); 8 | uint8_t ICACHE_FLASH_ATTR UTILS_IsIPV4 (int8_t *str); 9 | #endif 10 | -------------------------------------------------------------------------------- /include/main.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MAIN_H 3 | #define _MAIN_H 4 | 5 | #include "console.h" 6 | 7 | struct slogger_instance; 8 | struct slogger_instance *svclog_get_global_instance(); 9 | 10 | #define FR_CONSTRUCTOR(fn) \ 11 | static void fn(); \ 12 | __attribute__((__section__(".fr_init_array"))) void *fn ## _high = fn; \ 13 | static void __attribute__((__used__)) fn() 14 | 15 | 16 | extern printf_f console_printf; // = ets_uart_printf; 17 | 18 | void request_default_environment(void); 19 | void print_hello_banner(void); 20 | const char* fr_request_hostname(void); 21 | 22 | #endif // _MAIN_H 23 | -------------------------------------------------------------------------------- /include/missing.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MISSING_H_ 3 | #define _MISSING_H 4 | 5 | //#error remove dependencies to missing.h, it is now empty :) 6 | 7 | // all of this should go to antares 8 | 9 | #include "user_interface.h" 10 | // this should go to antares user_interface.h 11 | //struct ip_info { 12 | // struct ip_addr ip; 13 | // struct ip_addr netmask; 14 | // struct ip_addr gw; 15 | //}; 16 | 17 | void ets_intr_lock (void); 18 | void ets_intr_unlock (void); 19 | 20 | #endif // _MISSING_H_ 21 | -------------------------------------------------------------------------------- /include/pin_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * There is not a 1:1 mapping between physical pin numbers numbers and the 3 | * various constants uses to control GPIO functionality. 4 | * 5 | * The following globals are used to make this easy without adding masses of 6 | * overhead that a fully fledged abstraction library (such as that provided by 7 | * Arduino) might add: 8 | * 9 | * pin_mux[gpio] ->> returns the correct constant for gpio 'pin' to use 10 | * as the first argument to PIN_FUNC_SELECT(), 11 | * PIN_PULLDWN_DIS(), PIN_PULLUP_DIS(), PIN_PULLUP_EN(), 12 | * PIN_PULLDWN_DIS() functions 13 | * 14 | * pin_func[gpio] ->> returns the correct constant for gpio 'gpio' to use 15 | * as the second argument to PIN_FUNC_SELECT() 16 | * 17 | * The gpio is passed directly to GPIO_DIS_OUTPUT(), GPIO_OUTPUT_SET() and 18 | * GPIO_OUTPUT_GET() 19 | * 20 | * pin_int_type[gpio] is used to return the GPIO_PIN_INTR_DISABLE state when 21 | * GPIO interrupts are enabled. 22 | * 23 | * The actual mappings are described in the file pin_map.c 24 | * 25 | * Not all gpio numbers are valid. This can be checked first using the function 26 | * is_valid_gpio_pin() which also checks for the gpio in the range 27 | * 0..GPIO_PIN_NUM-1 28 | * 29 | * Invalid gpio will also report -1 for pin_mux[] and pin_func[] 30 | * 31 | * Note that the ESP SDK provides an additional macro, GPIO_ID_PIN() which in 32 | * theory should be wrapped around all 'gpio' numbers passed to the register 33 | * functions, however, this macro essentially resolves to a NO-OP so code will 34 | * work fine without it. It is not inconceivable however that there could be 35 | * a future hardware version increment that breaks this, so I guess omit this 36 | * at your own risk. 37 | * 38 | * EXAMPLE 39 | * ------- 40 | * 41 | * uint8_t gpio = argv[2]; 42 | * if (!is_valid_gpio_pin(gpio)) { printf("error...\n"); return; } 43 | * PIN_FUNC_SELECT(pin_mux[gpio], pin_func[gpio]); 44 | * PIN_PULLDWN_DIS(pin_mux[gpio]); 45 | * GPIO_DIS_OUTPUT(GPIO_ID_PIN(gpio)); 46 | * 47 | */ 48 | #ifndef __PIN_MAP_H__ 49 | #define __PIN_MAP_H__ 50 | 51 | #include "c_types.h" 52 | #include "user_config.h" 53 | #include "gpio.h" 54 | 55 | #define GPIO_PIN_NUM 17 56 | #define GPIO_PIN_FUNC_INVALID (uint8_t)(-1) 57 | #define GPIO_PIN_MUX_INVALID (uint32_t)(-1) 58 | 59 | extern bool is_valid_gpio_pin(uint8 gpiopin); 60 | 61 | //extern uint8_t pin_num[GPIO_PIN_NUM]; 62 | extern uint8_t pin_func[GPIO_PIN_NUM]; 63 | extern uint32_t pin_mux[GPIO_PIN_NUM]; 64 | #ifdef GPIO_INTERRUPT_ENABLE 65 | extern GPIO_INT_TYPE pin_int_type[GPIO_PIN_NUM]; 66 | #endif 67 | #endif // #ifndef __PIN_MAP_H__ 68 | -------------------------------------------------------------------------------- /include/sched.h: -------------------------------------------------------------------------------- 1 | void sched_init(void); 2 | int sched_add(const char *, int); 3 | void sched_run(const char *); 4 | -------------------------------------------------------------------------------- /include/svc_telnet.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _SVC_TELNET_H_ 3 | #define _SVC_TELNET_H_ 4 | 5 | void telnet_start (int port); 6 | 7 | #endif // _SVC_TELNET_H 8 | -------------------------------------------------------------------------------- /include/user_config.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekromant/esp8266-frankenstein/3188970703aceb67587f6081baa2ae5cc8bf9350/include/user_config.h -------------------------------------------------------------------------------- /mkespfsimage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(mkespfsimage) 3 | add_executable(mkespfsimage main.c heatshrink_encoder.c) 4 | include_directories(${CMAKE_SOURCE_DIR}/../src/heatshrink) 5 | include_directories(${CMAKE_SOURCE_DIR}/../include) 6 | add_definitions(-std=gnu99) 7 | -------------------------------------------------------------------------------- /mkespfsimage/Makefile: -------------------------------------------------------------------------------- 1 | 2 | CFLAGS=-I../src/heatshrink -I../include -std=gnu99 3 | OBJS=main.o heatshrink_encoder.o 4 | TARGET=mkespfsimage 5 | 6 | $(TARGET): $(OBJS) 7 | $(CC) -o $@ $^ 8 | 9 | clean: 10 | rm -f $(TARGET) $(OBJS) 11 | -------------------------------------------------------------------------------- /mkespfsimage/espfsformat.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPROFSFORMAT_H 2 | #define ESPROFSFORMAT_H 3 | 4 | /* 5 | Stupid cpio-like tool to make read-only 'filesystems' that live on the flash SPI chip of the module. 6 | Can (will) use lzf compression (when I come around to it) to make shit quicker. Aligns names, files, 7 | headers on 4-byte boundaries so the SPI abstraction hardware in the ESP8266 doesn't crap on itself 8 | when trying to do a <4byte or unaligned read. 9 | */ 10 | 11 | /* 12 | The idea 'borrows' from cpio: it's basically a concatenation of {header, filename, file} data. 13 | Header, filename and file data is 32-bit aligned. The last file is indicated by data-less header 14 | with the FLAG_LASTFILE flag set. 15 | */ 16 | 17 | 18 | #define FLAG_LASTFILE (1<<0) 19 | #define COMPRESS_NONE 0 20 | #define COMPRESS_HEATSHRINK 1 21 | 22 | typedef struct { 23 | int32_t magic; 24 | int8_t flags; 25 | int8_t compression; 26 | int16_t nameLen; 27 | int32_t fileLenComp; 28 | int32_t fileLenDecomp; 29 | } __attribute__((packed)) EspFsHeader; 30 | 31 | #endif -------------------------------------------------------------------------------- /mkespfsimage/heatshrink_encoder.c: -------------------------------------------------------------------------------- 1 | //Stupid wraparound include to make sure object file doesn't end up in heatshrink dir 2 | 3 | #include "../src/heatshrink/heatshrink_encoder.c" 4 | -------------------------------------------------------------------------------- /mkespfsimage/out.espfs: -------------------------------------------------------------------------------- 1 | ESfs index.htmlWOOT!x 2 | ESfs -------------------------------------------------------------------------------- /scripts/iromify: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CROSS_COMPILE=$1 4 | shift 5 | MODE=$1 6 | shift 7 | 8 | OBJDUMP=${CROSS_COMPILE}-objdump 9 | OBJCOPY=${CROSS_COMPILE}-objcopy 10 | 11 | function iromify_file() { 12 | file=$1 13 | echo "[IROMIFY] $file" 14 | for section in `${OBJDUMP} -h $file|grep text|grep -v irom|grep -v iram|awk '{print $2}'`; do 15 | sname=`echo $section|sed 's/.text.//'`; 16 | ${OBJCOPY} --rename-section .text.$sname=.irom0.text.$sname \ 17 | --rename-section .literal.$sname=.irom0.literal.$sname $file; 18 | done; 19 | 20 | ${OBJCOPY} --rename-section .text=.irom0.text \ 21 | --rename-section .literal=.irom0.literal $file; 22 | } 23 | 24 | if [ "$MODE" == "OBJECT" ]; then 25 | for src in $*; do 26 | find $dir -type f -iname "*.obj"| grep $src | while read file; do 27 | iromify_file $file 28 | done 29 | done 30 | else 31 | for file in $*; do 32 | iromify_file $* 33 | done 34 | fi 35 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=main.o stdio.o helpers.o flash_end_marker.o 2 | objects-y+=microrl.o 3 | objects-y+=console.o 4 | # useless objects-y+=hostname.o 5 | objects-y+=env.o 6 | objects-$(CONFIG_SERVICE_TCP)+=cbuf.o 7 | objects-$(CONFIG_SERVICE_TCP)+=cbuftools.o 8 | objects-$(CONFIG_SERVICE_TCP)+=tcpservice.o 9 | objects-$(CONFIG_SERVICE_TELNET)+=svc_telnet.o 10 | objects-$(CONFIG_SERVICE_ECHO)+=svc_echo.o 11 | 12 | objects-y+=cmd_common.o cmd_env.o uart.o 13 | objects-y+=pin_map.o 14 | objects-y+=iwconnect.o 15 | 16 | objects-$(CONFIG_CMD_IW)+=cmd_iw.o 17 | objects-$(CONFIG_CMD_UART)+=cmd_uart.o 18 | objects-$(CONFIG_CMD_IF)+=cmd_ifconfig.o 19 | objects-$(CONFIG_CMD_GPIO)+=cmd_gpio.o 20 | objects-$(CONFIG_CMD_FLASH)+=cmd_flash.o 21 | objects-$(CONFIG_CMD_LISTEN)+=cmd_listen.o 22 | objects-$(CONFIG_CMD_SEND)+=cmd_send.o 23 | objects-$(CONFIG_CMD_DS18B20)+=cmd_ds18b20.o 24 | objects-$(CONFIG_CMD_DHT22)+=cmd_dht22.o 25 | objects-$(CONFIG_CMD_TFTP)+=cmd_tftp.o tftp.o 26 | objects-$(CONFIG_CMD_AT)+=cmd_at.o 27 | objects-$(CONFIG_CMD_ADC)+=cmd_adc.o 28 | objects-$(CONFIG_CMD_NSLOOKUP)+=cmd_nslookup.o 29 | #objects-$(CONFIG_CMD_PING)+=cmd_ping.o 30 | #objects-$(CONFIG_ENABLE_PASSTHROUGH)+=cmd_passthrough.o 31 | objects-$(CONFIG_CMD_PHY)+=cmd_wiphy.o 32 | 33 | objects-$(CONFIG_CMD_I2C)+=cmd_i2c.o i2c_master.o 34 | objects-$(CONFIG_CMD_I2C_BMP180)+=i2c_bmp180.o 35 | objects-$(CONFIG_CMD_I2C_INA219)+=i2c_ina219.o 36 | objects-$(CONFIG_CMD_I2C_SHT21)+=i2c_sht21.o 37 | objects-$(CONFIG_CMD_I2C_SI7020)+=i2c_si7020.o 38 | objects-$(CONFIG_CMD_I2C_BH1750)+=i2c_bh1750.o 39 | objects-$(CONFIG_CMD_I2C_PCF8591)+=i2c_pcf8591.o 40 | objects-$(CONFIG_CMD_I2C_HMC5883L)+=i2c_hmc5883l.o 41 | objects-$(CONFIG_CMD_I2C_TCS3414CS)+=i2c_tcs3414cs.o 42 | objects-$(CONFIG_CMD_I2C_MLX90614)+=i2c_mlx90614.o 43 | 44 | ifneq ($(CONFIG_ESP8266_BLOB_LWIP),y) 45 | objects-y+=esp_timer.o 46 | subdirs-y+=lwip-app/ 47 | ifeq ($(CONFIG_LWIP_ESP),y) 48 | subdirs-y+=lwip-esp 49 | endif 50 | ifeq ($(CONFIG_LWIP_GIT),y) 51 | subdirs-y+=lwip-git 52 | endif 53 | endif 54 | 55 | objects-$(CONFIG_ENABLE_MQTT)+=cmd_mqtt.o 56 | subdirs-y+=mqtt 57 | 58 | objects-$(CONFIG_ENABLE_SCHED)+=sched.o 59 | 60 | -------------------------------------------------------------------------------- /src/base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | base64.c - by Joe DF (joedf@ahkscript.org) 3 | Released under the MIT License 4 | 5 | See "base64.h", for more information. 6 | 7 | Thank you for inspiration: 8 | http://www.codeproject.com/Tips/813146/Fast-base-functions-for-encode-decode 9 | */ 10 | 11 | #include "base64.h" 12 | 13 | //Base64 char table - used internally for encoding 14 | unsigned char b64_chr[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 15 | 16 | unsigned int b64_int(unsigned int ch) { 17 | 18 | // ASCII to base64_int 19 | // 65-90 Upper Case >> 0-25 20 | // 97-122 Lower Case >> 26-51 21 | // 48-57 Numbers >> 52-61 22 | // 43 Plus (+) >> 62 23 | // 47 Slash (/) >> 63 24 | // 61 Equal (=) >> 64~ 25 | if (ch==43) 26 | return 62; 27 | if (ch==47) 28 | return 63; 29 | if (ch==61) 30 | return 64; 31 | if ((ch>47) && (ch<58)) 32 | return ch + 4; 33 | if ((ch>64) && (ch<91)) 34 | return ch - 'A'; 35 | if ((ch>96) && (ch<123)) 36 | return (ch - 'a') + 26; 37 | return 0; 38 | } 39 | 40 | unsigned int b64e_size(unsigned int in_size) { 41 | 42 | // size equals 4*floor((1/3)*(in_size+2)); 43 | int i, j = 0; 44 | for (i=0;i>2 ]; 64 | out[k+1] = b64_chr[ ((s[0]&0x03)<<4)+((s[1]&0xF0)>>4) ]; 65 | out[k+2] = b64_chr[ ((s[1]&0x0F)<<2)+((s[2]&0xC0)>>6) ]; 66 | out[k+3] = b64_chr[ s[2]&0x3F ]; 67 | j=0; k+=4; 68 | } 69 | } 70 | 71 | if (j) { 72 | if (j==1) 73 | s[1] = 0; 74 | out[k+0] = b64_chr[ s[0]>>2 ]; 75 | out[k+1] = b64_chr[ ((s[0]&0x03)<<4)+((s[1]&0xF0)>>4) ]; 76 | if (j==2) 77 | out[k+2] = b64_chr[ ((s[1]&0x0F)<<2) ]; 78 | else 79 | out[k+2] = '='; 80 | out[k+3] = '='; 81 | k+=4; 82 | } 83 | 84 | out[k] = '\0'; 85 | 86 | return k; 87 | } 88 | 89 | unsigned int b64_decode(const unsigned char* in, unsigned int in_len, unsigned int* out) { 90 | 91 | unsigned int i=0, j=0, k=0, s[4]; 92 | 93 | for (i=0;i>4); 97 | if (s[2]!=64) { 98 | out[k+1] = ((s[1]&0x0F)<<4)+((s[2]&0x3C)>>2); 99 | if ((s[3]!=64)) { 100 | out[k+2] = ((s[2]&0x03)<<6)+(s[3]); k+=3; 101 | } else { 102 | k+=2; 103 | } 104 | } else { 105 | k+=1; 106 | } 107 | j=0; 108 | } 109 | } 110 | 111 | return k; 112 | } 113 | -------------------------------------------------------------------------------- /src/cbuftools.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | #include "cbuftools.h" 7 | 8 | char sprintbuf__ [SPRINTBUFSIZE]; 9 | 10 | void tooshortbuf (char* str, size_t size) 11 | { 12 | static const char tooshortbuf [] = ">>><"; 13 | size_t shift = (size < sizeof tooshortbuf)? sizeof tooshortbuf - 1 - size: 0; 14 | strcpy(str + size + shift - (sizeof tooshortbuf - 1), tooshortbuf + shift); 15 | } 16 | 17 | int cbuf_printf (cbuf_t* cb, const char* fmt, ...) 18 | { 19 | int ret; 20 | va_list ap; 21 | va_start(ap, fmt); 22 | ret = cbuf_vprintf(cb, fmt, ap); 23 | va_end(ap); 24 | return ret; 25 | } 26 | 27 | int cbuf_vprintf (cbuf_t* cb, const char* fmt, va_list ap) 28 | { 29 | size_t cbavail = cbuf_write_available(cb); 30 | if (cbavail + 1 > SPRINTBUFSIZE) 31 | cbavail = SPRINTBUFSIZE - 1; 32 | 33 | if (vsnprintf(sprintbuf__, cbavail + 1, fmt, ap) >= cbavail + 1) 34 | tooshortbuf(sprintbuf__, cbavail + 1); 35 | 36 | return cbuf_write(cb, sprintbuf__, strlen(sprintbuf__)); 37 | } 38 | -------------------------------------------------------------------------------- /src/cmd_adc.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "c_types.h" 5 | #include "console.h" 6 | #include "user_interface.h" 7 | 8 | static int do_adc (int argc, const char* const* argv) 9 | { 10 | console_printf("%d\n", system_adc_read()); 11 | return 0; 12 | } 13 | 14 | CONSOLE_CMD(adc, 1, 1, 15 | do_adc, NULL, NULL, 16 | "Reads system ADC value" 17 | ); 18 | -------------------------------------------------------------------------------- /src/cmd_at.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "console.h" 4 | #include "user_interface.h" 5 | #include "lwip/init.h" 6 | 7 | #if TTDBG 8 | int ttdbg[TTDBG] = 9 | { 10 | -1, -1, -1, -1, -1, -1, -1, -1, 11 | -1, -1, -1, -1, -1, -1, -1, -1, 12 | -1, -1, -1, -1, -1, -1, -1, -1, 13 | -1, -1, -1, -1, -1, -1, -1, -1, 14 | -1, -1, -1, -1, -1, -1, -1, -1, 15 | -1, -1, -1, -1, -1, -1, -1, -1, 16 | -1, -1, -1, -1, -1, -1, -1, -1, 17 | -1, -1, -1, -1, -1, -1, -1, -1, 18 | }; 19 | #endif 20 | 21 | static int do_at (int argc, const char* const* argv) 22 | { 23 | unsigned char stamacaddr[6]; 24 | unsigned char apmacaddr[6]; 25 | wifi_get_macaddr(STATION_IF, stamacaddr); 26 | wifi_get_macaddr(SOFTAP_IF, apmacaddr); 27 | console_printf("OK heap=%d sdk=%s stamac=" MACSTR " apmac=" MACSTR " chipid=0x%0x lwip=%x mss=%d tcpwnd=%d\n", 28 | system_get_free_heap_size(), 29 | system_get_sdk_version(), 30 | MAC2STR(stamacaddr), 31 | MAC2STR(apmacaddr), 32 | system_get_chip_id(), 33 | LWIP_VERSION, TCP_MSS, TCP_WND); 34 | 35 | #if TTDBG 36 | int x, y = 1; 37 | while (argc >= y + 2) 38 | { 39 | x = atoi(argv[y]); 40 | if (x >= 0 && x < TTDBG) 41 | ttdbg[x] = atoi(argv[y + 1]); 42 | y += 2; 43 | } 44 | for (x = 0; x < TTDBG; x+=8) 45 | { 46 | for (y = x; y < x + 8; y++) 47 | console_printf("%02d:0x%08x ", y, ttdbg[y]); 48 | console_printf("\n"); 49 | } 50 | #endif 51 | 52 | return 0; 53 | } 54 | 55 | CONSOLE_CMD(AT, 1, 10, 56 | do_at, NULL, NULL, 57 | "says OK" 58 | ); 59 | -------------------------------------------------------------------------------- /src/cmd_env.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | #include "env.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | 20 | static int do_printenv(int argc, const char* const* argv) 21 | { 22 | env_dump(); 23 | return 0; 24 | } 25 | 26 | static int do_reset(int argc, const char* const* argv) 27 | { 28 | console_printf("Reverting to default env.."); 29 | env_reset(); 30 | console_printf(".DONE!\n"); 31 | return 0; 32 | } 33 | 34 | static int do_setenv(int argc, const char* const* argv) 35 | { 36 | switch (argc) 37 | { 38 | case 1: 39 | env_dump(); 40 | break; 41 | case 2: 42 | env_delete(argv[1]); 43 | break; 44 | case 3: 45 | env_insert(argv[1], argv[2]); 46 | break; 47 | } 48 | return 0; 49 | } 50 | 51 | static int do_getenv(int argc, const char* const* argv) 52 | { 53 | const char *v = env_get(argv[1]); 54 | if (v) 55 | console_printf(v); 56 | else 57 | console_printf("(not set)\n"); 58 | return 0; 59 | } 60 | 61 | static int do_saveenv(int argc, const char* const* argv) 62 | { 63 | console_printf("Writing environment to flash.."); 64 | env_save(); 65 | console_printf(".DONE\n"); 66 | return 0; 67 | } 68 | 69 | CONSOLE_CMD(printenv, 1, 1, 70 | do_printenv, NULL, NULL, 71 | "Print all environment variables" 72 | ); 73 | 74 | CONSOLE_CMD(setenv, 3, 3, 75 | do_setenv, NULL, NULL, 76 | "Set an environment variable" 77 | HELPSTR_NEWLINE "setenv var value" 78 | ); 79 | 80 | CONSOLE_CMD(getenv, 2, 2, 81 | do_getenv, NULL, NULL, 82 | "Get an environment variable" 83 | HELPSTR_NEWLINE "getenv var" 84 | ); 85 | 86 | CONSOLE_CMD(saveenv, 1, 1, 87 | do_saveenv, NULL, NULL, 88 | "Write environment to flash" 89 | HELPSTR_NEWLINE "setenv var value" 90 | ); 91 | 92 | CONSOLE_CMD(envreset, 1, 1, 93 | do_reset, NULL, NULL, 94 | "Reset environment to defaults" 95 | HELPSTR_NEWLINE "resetenv" 96 | ); 97 | -------------------------------------------------------------------------------- /src/cmd_gpio.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | static int do_gpio(int argc, const char* const* argv) 19 | { 20 | int gpio = atoi(argv[2]); 21 | 22 | if (strcmp(argv[1], "in") == 0) { 23 | GPIO_DIS_OUTPUT(gpio); 24 | console_printf("GP%d==%d\n", gpio, GPIO_INPUT_GET(gpio)); 25 | } else if (strcmp(argv[1], "out") == 0) { 26 | if (argc < 4) 27 | return -1; 28 | int v = atoi(argv[3]); 29 | GPIO_OUTPUT_SET(gpio, v); 30 | } 31 | return 0; 32 | } 33 | 34 | CONSOLE_CMD(gpio, 3, 4, 35 | do_gpio, NULL, NULL, 36 | "Control gpio lines. gpio mode line [value] " 37 | HELPSTR_NEWLINE "gpio in 0" 38 | HELPSTR_NEWLINE "gpio out 0 1" 39 | ); 40 | 41 | #ifdef CONFIG_ENABLE_MQTT 42 | #include "lib/mqtt.h" 43 | 44 | /* 45 | * Is this a reasonable limit? 46 | */ 47 | #define TOPIC_LEN 128 48 | 49 | void ICACHE_FLASH_ATTR 50 | gpio_sub_handler(const char *gpiostr, const char *arg) 51 | { 52 | int gpio = atoi(gpiostr); 53 | int data = atoi(arg); 54 | 55 | /* TODO: Range check GPIO here */ 56 | if (data == 0 || data == 1) 57 | GPIO_OUTPUT_SET(gpio, data); 58 | } 59 | 60 | static int ICACHE_FLASH_ATTR 61 | do_gpio_sub(int argc, const char* const* argv) 62 | { 63 | return MQTT_Do_Subscribe("gpio", argv[1], gpio_sub_handler); 64 | } 65 | 66 | static int ICACHE_FLASH_ATTR 67 | do_gpio_pub(int argc, const char* const* argv) 68 | { 69 | MQTT_Client *client = mqttGetConnectedClient(); 70 | int gpio = atoi(argv[1]); 71 | char buf[6]; 72 | int buflen; 73 | char topic[TOPIC_LEN]; 74 | 75 | if (client == NULL) { 76 | console_printf("MQTT Client not bound to broker\r\n"); 77 | return -1; 78 | } 79 | 80 | os_sprintf(topic, "%s/gpio/status/%d", client->connect_info.client_id, gpio); 81 | 82 | buflen = os_sprintf(buf, "%d", GPIO_INPUT_GET(gpio)); 83 | MQTT_Publish(client, topic, buf, buflen, 0, 0); 84 | return 0; 85 | } 86 | 87 | CONSOLE_CMD(gpio_sub, 2,2, 88 | do_gpio_sub, NULL, NULL, 89 | "Subscribe to GPIO" 90 | HELPSTR_NEWLINE 91 | "gpio_sub " 92 | ); 93 | 94 | CONSOLE_CMD(gpio_pub, 2,2, 95 | do_gpio_pub, NULL, NULL, 96 | "Publish GPIO state" 97 | HELPSTR_NEWLINE 98 | "gpio_pub " 99 | ); 100 | 101 | #endif // CONFIG_ENABLE_MQTT 102 | -------------------------------------------------------------------------------- /src/cmd_mqtt.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "driver/uart.h" 9 | #include "microrl.h" 10 | #include "console.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include "lib/mqtt.h" 16 | #include "lib/config.h" 17 | 18 | MQTT_Client mqttClient; 19 | MQTT_Client* mqttConnectedClient; 20 | 21 | MQTT_Client * 22 | mqttGetConnectedClient(void) 23 | { 24 | return mqttConnectedClient; 25 | } 26 | 27 | void mqttConnectedCb(uint32_t *args) 28 | { 29 | mqttConnectedClient = (MQTT_Client *)args; 30 | return; 31 | } 32 | 33 | void mqttDisconnectedCb(uint32_t *args) 34 | { 35 | mqttConnectedClient = (MQTT_Client *)NULL; 36 | return; 37 | } 38 | 39 | void mqttPublishedCb(uint32_t *args) 40 | { 41 | return; 42 | } 43 | 44 | void mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) 45 | { 46 | char *topicBuf = (char*)os_zalloc(topic_len+1), 47 | *dataBuf = (char*)os_zalloc(data_len+1); 48 | 49 | os_memcpy(topicBuf, topic, topic_len); 50 | topicBuf[topic_len] = 0; 51 | 52 | os_memcpy(dataBuf, data, data_len); 53 | dataBuf[data_len] = 0; 54 | 55 | console_printf("Receive topic: %s, data: %s \r\n", topicBuf, dataBuf); 56 | MQTT_Call_Subscribe_Handler(topicBuf, dataBuf); 57 | 58 | os_free(topicBuf); 59 | os_free(dataBuf); 60 | } 61 | 62 | 63 | 64 | 65 | static int do_startmqtt(int argc, const char* const* argv) 66 | { 67 | CFG_Load(); 68 | 69 | MQTT_InitConnection(&mqttClient, (uint8_t *)sysCfg.mqtt_host, sysCfg.mqtt_port, 0); 70 | MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1); 71 | 72 | MQTT_InitLWT(&mqttClient, (uint8_t *)"/lwt", (uint8_t *)"offline", 0, 0); 73 | MQTT_OnConnected(&mqttClient, mqttConnectedCb); 74 | MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb); 75 | MQTT_OnPublished(&mqttClient, mqttPublishedCb); 76 | MQTT_OnData(&mqttClient, mqttDataCb); 77 | MQTT_Connect(&mqttClient); 78 | 79 | return 0; 80 | } 81 | 82 | static int do_stopmqtt(int argc, const char* const* argv) 83 | { 84 | MQTT_Disconnect(&mqttClient); 85 | return 0; 86 | } 87 | 88 | static int do_mqttpub(int argc, const char* const* argv) 89 | { 90 | if (argc < 3) 91 | return -1; 92 | 93 | if (mqttConnectedClient != NULL) 94 | MQTT_Publish(mqttConnectedClient, argv[1], argv[2], strlen(argv[2]), 0, 0); 95 | return 0; 96 | } 97 | 98 | static int do_mqttsub(int argc, const char* const* argv) 99 | { 100 | if (argc < 2) 101 | return -1; 102 | 103 | if (mqttConnectedClient != NULL) 104 | MQTT_Subscribe(mqttConnectedClient, argv[1], 0); 105 | return 0; 106 | } 107 | 108 | CONSOLE_CMD(startmqtt, 1, 1, 109 | do_startmqtt, NULL, NULL, 110 | "Start MQTT Service" 111 | ); 112 | 113 | CONSOLE_CMD(stopmqtt, 1, 1, 114 | do_stopmqtt, NULL, NULL, 115 | "Stop MQTT Service" 116 | ); 117 | 118 | CONSOLE_CMD(mqttpub, 3, 3, 119 | do_mqttpub, NULL, NULL, 120 | "Publish MQTT" 121 | ); 122 | 123 | CONSOLE_CMD(mqttsub, 2, 2, 124 | do_mqttsub, NULL, NULL, 125 | "Subscribe MQTT" 126 | ); 127 | -------------------------------------------------------------------------------- /src/cmd_nslookup.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "microrl.h" 9 | #include "console.h" 10 | 11 | #include 12 | #include 13 | 14 | static void nslookup_callback(const char *name, ip_addr_t *ipaddr, void *arg) 15 | { 16 | if (ipaddr==NULL) { 17 | console_printf("nslookup failed\n"); 18 | }else{ 19 | console_printf("%d.%d.%d.%d\n" , IP2STR(&ipaddr->addr)); 20 | } 21 | console_lock(0); 22 | } 23 | 24 | static int do_nslookup(int argc, const char* const* argv) 25 | { 26 | struct espconn pespconn; 27 | ip_addr_t ipaddr; 28 | espconn_gethostbyname(&pespconn, argv[1], &ipaddr, nslookup_callback); 29 | console_lock(1); 30 | return 0; 31 | } 32 | 33 | CONSOLE_CMD(nslookup, 2, 2, 34 | do_nslookup, NULL, NULL, 35 | "Get IP address via hostname." 36 | HELPSTR_NEWLINE "nslookup google.com" 37 | ); 38 | -------------------------------------------------------------------------------- /src/cmd_passthrough.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "console.h" 4 | #include "user_interface.h" 5 | 6 | #if 1 7 | 8 | 9 | static int do_passthrough (int argc, const char* const* argv) 10 | { 11 | return 0; 12 | } 13 | 14 | CONSOLE_CMD(passthrough, 1, 1, 15 | do_passthrough, NULL, NULL, 16 | "disable console, setup direct link through serial port" 17 | HELPSTR_NEWLINE "disabled by pressing ESC some times" 18 | ); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/cmd_ping.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "microrl.h" 9 | #include "console.h" 10 | #include "ping.h" 11 | 12 | #include 13 | #include 14 | 15 | //TODO: cmd_ping.c:(.irom0.text+0x2d): undefined reference to `ping_start' 16 | 17 | static void ping_recv_callback(void *arg, void *pdata) 18 | { 19 | struct ping_resp *pingresp = pdata; 20 | 21 | console_printf("recv %d bytes in %d ms, seq %d (%d)\n", pingresp->bytes, pingresp->resp_time, pingresp->seqno, pingresp->ping_err); 22 | if (pingresp->seqno == 3 /*LAST PING PACKET*/) { 23 | console_printf("total %d, lost %d, %d bytes, %d ms (%d)\n", 24 | pingresp->total_count, pingresp->timeout_count, pingresp->total_bytes, pingresp->total_time, pingresp->ping_err); 25 | console_lock(0); 26 | os_free(arg); 27 | } 28 | } 29 | 30 | static int do_ping(int argc, const char *const *argv) 31 | { 32 | struct ping_option *pingopts = os_zalloc(sizeof(struct ping_option)); 33 | ip_addr_t ipaddr; 34 | 35 | ipaddr.addr = ipaddr_addr(argv[1]); 36 | 37 | pingopts->ip = ipaddr.addr; 38 | pingopts->count = 3; 39 | pingopts->recv_function = ping_recv_callback; 40 | pingopts->sent_function = NULL; 41 | ping_start(pingopts); 42 | console_lock(1); 43 | return 0; 44 | } 45 | 46 | CONSOLE_CMD(ping, 2, 2, 47 | do_ping, NULL, NULL, 48 | "Send icmp ping to specified address" 49 | HELPSTR_NEWLINE "ping 8.8.8.8" 50 | ); 51 | -------------------------------------------------------------------------------- /src/cmd_send.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | 13 | #include 14 | #include 15 | 16 | 17 | struct pokerface { 18 | struct espconn esp_conn; 19 | esp_tcp esptcp; 20 | char databuf[128]; 21 | int datalen; 22 | /*volatile*/ os_timer_t conn_checker; 23 | }; 24 | 25 | static void conn_checker_handler(void *arg) 26 | { 27 | struct pokerface *p = arg; 28 | /* Lazy gc */ 29 | os_free(p); 30 | LOG(LOG_DEBUG, "free!\n"); 31 | 32 | } 33 | 34 | static void connected(void *arg) 35 | { 36 | struct pokerface *p = arg; 37 | espconn_sent(&p->esp_conn, (uint8*)p->databuf, p->datalen); 38 | } 39 | 40 | static void disconnected(void *arg) 41 | { 42 | console_printf("OK\n"); 43 | console_lock(0); 44 | struct pokerface *p = arg; 45 | os_timer_arm(&p->conn_checker, 50, 0); 46 | 47 | } 48 | 49 | static void reconnect(void *arg, sint8 err) 50 | { 51 | console_printf("Error %d\n", err); 52 | struct pokerface *p = arg; 53 | espconn_disconnect(&p->esp_conn); 54 | console_lock(0); 55 | } 56 | 57 | static void datasent(void *arg) 58 | { 59 | struct pokerface *p = arg; 60 | os_timer_disarm(&p->conn_checker); 61 | os_timer_setfn(&p->conn_checker, (os_timer_func_t *)conn_checker_handler, p); 62 | espconn_disconnect(&p->esp_conn); 63 | } 64 | 65 | 66 | static int do_send(int argc, const char* const* argv) 67 | { 68 | struct pokerface *p = os_zalloc(sizeof(struct pokerface)); 69 | if (!p) { 70 | console_printf("Can't malloc enough to send\n"); 71 | return -1; 72 | } 73 | 74 | int port = atoi(argv[2]); 75 | p->esp_conn.type = ESPCONN_TCP; 76 | p->esp_conn.state = ESPCONN_NONE; 77 | p->esp_conn.proto.tcp = &p->esptcp; 78 | p->esp_conn.proto.tcp->local_port = espconn_port(); 79 | p->esp_conn.proto.tcp->remote_port = port; 80 | uint32_t target = ipaddr_addr(argv[1]); 81 | 82 | int i; 83 | p->databuf[0] = 0; 84 | for (i=3; idatabuf) + strlen(argv[i]) + 1) >= sizeof(p->databuf)) { 86 | console_printf("Total length of data exceeds buffer (max: %d characters)\n", sizeof(p->databuf)-1); 87 | os_free(p); 88 | return -1; 89 | } 90 | strcat(p->databuf, argv[i]); 91 | strcat(p->databuf, " "); 92 | } 93 | p->datalen = strlen(p->databuf); 94 | 95 | os_memcpy(p->esp_conn.proto.tcp->remote_ip, &target, 4); 96 | espconn_regist_connectcb(&p->esp_conn, connected); 97 | espconn_regist_reconcb(&p->esp_conn, reconnect); 98 | espconn_regist_disconcb(&p->esp_conn, disconnected); 99 | espconn_regist_sentcb(&p->esp_conn, datasent); 100 | espconn_connect(&p->esp_conn); 101 | console_lock(1); 102 | 103 | return 0; 104 | } 105 | 106 | static void do_send_interrupt(void) 107 | { 108 | 109 | } 110 | 111 | 112 | CONSOLE_CMD(send, 4, -1, 113 | do_send, do_send_interrupt, NULL, 114 | "Send data to a remote host. " 115 | HELPSTR_NEWLINE "send hostname port [data]" 116 | ); 117 | -------------------------------------------------------------------------------- /src/cmd_uart.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | 18 | static int do_baud(int argc, const char* const* argv) 19 | { 20 | int port = atoi(argv[1]); 21 | int speed = atoi(argv[2]); 22 | if (port > 1) { 23 | console_printf("We only have UART0 and UART1, sorry\n"); 24 | return -1; 25 | } 26 | 27 | console_printf("Setting UART%d speed to %d bps\n", port, speed); 28 | uart_init(port, speed); 29 | 30 | return 0; 31 | } 32 | 33 | CONSOLE_CMD(baud, 3, 3, 34 | do_baud, NULL, NULL, 35 | "Configure serial port speed" 36 | HELPSTR_NEWLINE "baudrate {port:0/1} {speed}" 37 | HELPSTR_NEWLINE "baudrate 0 57600" 38 | ); 39 | -------------------------------------------------------------------------------- /src/cmd_wiphy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "user_interface.h" 3 | 4 | #include "console.h" 5 | 6 | static int do_wiphy (int argc, const char* const* argv) 7 | { 8 | int ret = -1; 9 | enum phy_mode mode; 10 | if (argc == 1) 11 | { 12 | char pmode = '?'; 13 | mode = wifi_get_phy_mode(); 14 | ret = 0; 15 | switch (mode) 16 | { 17 | case PHY_MODE_11B: pmode = 'B'; break; 18 | case PHY_MODE_11G: pmode = 'G'; break; 19 | case PHY_MODE_11N: pmode = 'N'; break; 20 | default: ret = -1; 21 | } 22 | console_printf("phy mode: 802.11%c\n", pmode); 23 | } 24 | else if (argc == 2) 25 | { 26 | ret = 0; 27 | switch (argv[1][0]) 28 | { 29 | case 'b': 30 | case 'B': mode = PHY_MODE_11B; break; 31 | case 'g': 32 | case 'G': mode = PHY_MODE_11G; break; 33 | case 'n': 34 | case 'N': mode = PHY_MODE_11N; break; 35 | default: ret = -1; 36 | } 37 | if (ret != -1) 38 | { 39 | ret = wifi_set_phy_mode(mode)? 0: -1; 40 | do_wiphy(1, NULL); // display state 41 | } 42 | } 43 | return ret; 44 | } 45 | 46 | const char sleep_none[] = "none"; 47 | const char sleep_light[] = "light"; 48 | const char sleep_modem[] = "modem"; 49 | 50 | static int do_physleep (int argc, const char* const* argv) 51 | { 52 | int ret = -1; 53 | enum sleep_type mode; 54 | if (argc == 1) 55 | { 56 | const char* pmode = "?"; 57 | mode = wifi_get_sleep_type(); 58 | ret = 0; 59 | switch (mode) 60 | { 61 | case NONE_SLEEP_T: pmode = sleep_none; break; 62 | case LIGHT_SLEEP_T: pmode = sleep_light; break; 63 | case MODEM_SLEEP_T: pmode = sleep_modem; break; 64 | default: ret = -1; 65 | } 66 | console_printf("phy sleep mode: %s\n", pmode); 67 | } 68 | else if (argc == 2) 69 | { 70 | ret = 0; 71 | if (stricmp(argv[1], sleep_none) == 0) 72 | mode = NONE_SLEEP_T; 73 | else if (stricmp(argv[1], sleep_light) == 0) 74 | mode = LIGHT_SLEEP_T; 75 | else if (stricmp(argv[1], sleep_modem) == 0) 76 | mode = MODEM_SLEEP_T; 77 | else 78 | ret = -1; 79 | if (ret != -1) 80 | { 81 | ret = wifi_set_sleep_type(mode)? 0: -1; 82 | do_physleep(1, NULL); // display state 83 | } 84 | } 85 | return ret; 86 | } 87 | 88 | CONSOLE_CMD(wiphy, -1, -1, 89 | do_wiphy, NULL, NULL, 90 | "get/select wifi phy mode: B/G/N"); 91 | 92 | CONSOLE_CMD(physleep, -1, -1, 93 | do_physleep, NULL, NULL, 94 | "get/select wifi sleep mode: none/light/modem"); 95 | -------------------------------------------------------------------------------- /src/console_auth.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "ets_sys.h" 4 | #include "os_type.h" 5 | #include "mem.h" 6 | #include "osapi.h" 7 | #include "user_interface.h" 8 | 9 | #include "espconn.h" 10 | #include "gpio.h" 11 | #include "driver/uart.h" 12 | #include "microrl.h" 13 | #include "console.h" 14 | #include "env.h" 15 | #include 16 | 17 | #define MAX_AUTH_TOKEN_LEN 64 18 | 19 | struct auth_state { 20 | char buf[MAX_AUTH_TOKEN_LEN]; 21 | int pos; 22 | int state; 23 | }; 24 | 25 | 26 | void auth_reset(struct auth_state *s) 27 | { 28 | s->pos = 0; 29 | s->state = 0; 30 | memset(s->buf, 0x0, MAX_AUTH_TOKEN_LEN); 31 | char *hostname = env_get("hostname"); 32 | console_printf("\n\n\n%s login\n\n login: ", hostname); 33 | } 34 | 35 | void auth_success(struct auth_state *s) 36 | { 37 | console_set_charhandler(NULL, NULL); 38 | console_printf("\n\nWelcome to frankenstein's interactive shell!"); 39 | console_lock(0); 40 | os_free(s); 41 | } 42 | 43 | void auth_console_handler(void *arg, char c) 44 | { 45 | struct auth_state *s = arg; 46 | 47 | if ((c == '\n') || (c == '\r')) { 48 | if (!s->state) { 49 | if (strcmp(s->buf, "root") == 0) { 50 | s->state++; 51 | s->pos = 0; 52 | console_printf("\n password: "); 53 | } else { 54 | auth_reset(s); 55 | } 56 | } else { 57 | char *pwd = env_get("passwd"); 58 | if (!pwd) { 59 | console_printf("\n [!] No root password setup, use 'passwd' command to set one!\n"); 60 | auth_success(s); 61 | return; 62 | } 63 | 64 | char *tmp = alloca(b64e_size(strlen(s->buf) + 1)); 65 | b64_encode(s->buf, strlen(s->buf), tmp); 66 | if (strcmp(tmp, pwd) == 0) { 67 | auth_success(s); 68 | return; 69 | } 70 | console_printf("\nIncorrect password\n"); 71 | auth_reset(s); 72 | } 73 | } else { 74 | if (!s->state) 75 | console_printf("%c", c); 76 | else 77 | console_printf("*"); 78 | if (s->pos >= MAX_AUTH_TOKEN_LEN) { 79 | auth_reset(s); 80 | return; 81 | } 82 | s->buf[s->pos++] = c; 83 | } 84 | } 85 | 86 | void console_auth_start() 87 | { 88 | struct auth_state *state = os_malloc(sizeof(*state)); 89 | auth_reset(state); 90 | console_set_charhandler(auth_console_handler, state); 91 | console_lock(1); 92 | } 93 | 94 | 95 | static int do_passwd(int argc, const char *const *argv) 96 | { 97 | char *tmp = alloca(b64e_size(strlen(argv[1])+1)); 98 | b64_encode(argv[1], strlen(argv[1]), tmp); 99 | env_insert("passwd", tmp); 100 | env_save(); 101 | } 102 | 103 | CONSOLE_CMD(passwd, 2, -1, 104 | do_passwd, NULL, NULL, 105 | "Set up a root password" 106 | HELPSTR_NEWLINE "passwd topsecret" 107 | ); 108 | 109 | 110 | static int do_logout(int argc, const char *const *argv) 111 | { 112 | console_auth_start(); 113 | return 0; 114 | } 115 | 116 | CONSOLE_CMD(logout, 1, -1, 117 | do_logout, NULL, NULL, 118 | "Logout from this shell" 119 | HELPSTR_NEWLINE "logout" 120 | ); 121 | -------------------------------------------------------------------------------- /src/contrib/lwipupdate/diff-esp: -------------------------------------------------------------------------------- 1 | diff-git -------------------------------------------------------------------------------- /src/contrib/lwipupdate/diff-git: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | lwip=/tmp/lwip.git 4 | 5 | set -e 6 | #set -x 7 | 8 | dn="`cd \`dirname $0\`; pwd`" 9 | bn="`basename $0`" 10 | 11 | cd "$dn" 12 | vesp=`cat gitid-lwip-esp.txt` 13 | vgit=`cat gitid-lwip-git.txt` 14 | 15 | v="" 16 | test $bn = diff-esp && { v=$vesp; s=esp; } 17 | test $bn = diff-git -o $bn = diff-git-repatch && { v=$vgit; s=git; } 18 | 19 | if test -z "$v"; then 20 | echo "must be instantiated as 'diff-esp' or 'diff-git'" 21 | exit 1 22 | fi 23 | 24 | if test -d $lwip; then 25 | (cd $lwip && git stash && git checkout master) 26 | else 27 | git clone git://git.savannah.nongnu.org/lwip.git $lwip 28 | fi 29 | 30 | (cd $lwip && git checkout -f $v && diff -ruw src/ $dn/../../lwip-$s/) | grep -v '^Only in' > patch-lwip-$s.diff 31 | 32 | echo "" 33 | echo "just created 'patch-$s.diff' for lwip commit $v" 34 | echo "" 35 | -------------------------------------------------------------------------------- /src/contrib/lwipupdate/diff-git-repatch: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | . "`dirname $0`/diff-git" 4 | 5 | cd $lwip/src 6 | git checkout master 7 | git branch -d repatch-esp || true 8 | git branch repatch-esp 9 | git checkout repatch-esp 10 | patch -p1 < "$dn/patch-lwip-git.diff" || true 11 | echo "" 12 | echo "please review the above patch in '$lwip/' branch repatch-esp" 13 | echo "" 14 | -------------------------------------------------------------------------------- /src/contrib/lwipupdate/gitid-lwip-esp.txt: -------------------------------------------------------------------------------- 1 | 17d4ef40530f47cb96303a3f1a898936d0e4f3e4 2 | -------------------------------------------------------------------------------- /src/contrib/lwipupdate/gitid-lwip-git.txt: -------------------------------------------------------------------------------- 1 | 632de523de4d04ed069f46e18236b6b434372e5e 2 | -------------------------------------------------------------------------------- /src/esp-temp-lwip.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Finds the appropriate network interface for a source IP address. It 3 | * searches the list of network interfaces linearly. A match is found 4 | * if the masked IP address of the network interface equals the masked 5 | * IP address given to the function. 6 | * 7 | * @param source the sourcination IP address for which to find the route 8 | * @return the netif on which to send to reach source 9 | */ 10 | 11 | struct netif * 12 | ip_router(ip_addr_t *dest, ip_addr_t *source){ 13 | struct netif *netif; 14 | /* iterate through netifs */ 15 | for(netif = netif_list; netif != NULL; netif = netif->next) { 16 | /* network mask matches? */ 17 | 18 | if (netif_is_up(netif)) { 19 | if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { 20 | /* return netif on which to forward IP packet */ 21 | return netif; 22 | } 23 | } 24 | 25 | if (netif_is_up(netif)) { 26 | if (ip_addr_netcmp(source, &(netif->ip_addr), &(netif->netmask))) { 27 | /* return netif on which to forward IP packet */ 28 | return netif; 29 | } 30 | } 31 | } 32 | 33 | if ((netif_default == NULL) || (!netif_is_up(netif_default))) { 34 | LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", 35 | ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest))); 36 | IP_STATS_INC(ip.rterr); 37 | snmp_inc_ipoutnoroutes(); 38 | return NULL; 39 | } 40 | /* no matching netif found, use default netif */ 41 | return netif_default; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/esp_timer.c: -------------------------------------------------------------------------------- 1 | 2 | #include "lwip/opt.h" // extern sys_now_ms 3 | 4 | static u32_t last_now; 5 | static u32_t diff_m16; 6 | u32_t sys_now_ms; 7 | 8 | // old timer code from espressif: 9 | // sys_now_ms = (NOW() / ((CPU_CLK_FREQ / 1000) >> (timer2_ms_flag? 8: 4))) 10 | // which is (flag=1) sys_now() = NOW() / 312.5 11 | // and things break after several loops of NOW() (every 3.8hours, flag=1) 12 | // because sys_now_ms is going back instead of looping through its 2^32 range 13 | 14 | void esp_ms_timer_init (void) 15 | { 16 | last_now = NOW(); 17 | diff_m16 = 0; 18 | sys_now_ms = 0; 19 | } 20 | 21 | int esp_ms_timer_update_and_check_changed (void) 22 | { 23 | u32_t new_now = NOW(); // get raw timer2 register 24 | diff_m16 += (new_now - last_now) << 4; 25 | last_now = new_now; 26 | 27 | // ms_m16 is 16*(number of NOW() ticks for a milliseconds) 28 | u32_t ms_m16 = CPU_CLK_FREQ / 1000; 29 | if (timer2_ms_flag) 30 | // this is espressif magic 31 | // timer2_ms_flag seems to always be 1 but who knows ? 32 | ms_m16 >>= 4; 33 | 34 | if (diff_m16 < ms_m16) 35 | // unchanged 36 | return 0; 37 | 38 | #if 1 39 | // increase milliseconds according to ticks 40 | // we are called often enough to make only one loop 41 | while (diff_m16 >= ms_m16) 42 | { 43 | sys_now_ms++; 44 | diff_m16 -= ms_m16; 45 | } 46 | #else 47 | // XXX otherwise, divide and modulo should be faster 48 | divide and modulo 49 | #endif 50 | 51 | // changed 52 | return 1; 53 | } 54 | -------------------------------------------------------------------------------- /src/flash_end_marker.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | #include 13 | 14 | static __attribute__ ((used)) 15 | __attribute__((section(".firmware_end_marker"))) uint32_t flash_ends_here; 16 | 17 | /* 18 | Since flash's placed @ 0x40200000 we can easily calculate where to place user data 19 | */ 20 | 21 | 22 | uint32_t fr_get_firmware_last_loc() 23 | { 24 | return (uint32_t) &flash_ends_here; 25 | } 26 | 27 | uint32_t fr_get_firmware_size() 28 | { 29 | 30 | return (((uint32_t) &flash_ends_here) + sizeof(uint32_t) - 0x40200000); 31 | } 32 | 33 | uint32_t fr_fs_flash_offset() 34 | { 35 | uint32_t off = fr_get_firmware_size(); 36 | off += SPI_FLASH_SEC_SIZE; 37 | off &= ~(SPI_FLASH_SEC_SIZE - 1); 38 | return off; 39 | } 40 | 41 | void *fr_fs_physaddr() 42 | { 43 | return (void *) (fr_fs_flash_offset() + 0x40200000); 44 | } 45 | 46 | uint32_t fr_fs_size() 47 | { 48 | return env_get_flash_location() - fr_fs_flash_offset(); 49 | } 50 | -------------------------------------------------------------------------------- /src/heatshrink/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | compiler: 4 | - clang 5 | - gcc 6 | 7 | install: make test_heatshrink_dynamic 8 | 9 | script: ./test_heatshrink_dynamic 10 | -------------------------------------------------------------------------------- /src/heatshrink/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Scott Vokes 2 | All rights reserved. 3 | 4 | Permission to use, copy, modify, and/or distribute this software for any 5 | purpose with or without fee is hereby granted, provided that the above 6 | copyright notice and this permission notice appear in all copies. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | -------------------------------------------------------------------------------- /src/heatshrink/Makefile: -------------------------------------------------------------------------------- 1 | PROJECT = heatshrink 2 | #OPTIMIZE = -O0 3 | #OPTIMIZE = -Os 4 | OPTIMIZE = -O3 5 | WARN = -Wall -Wextra -pedantic #-Werror 6 | CFLAGS += -std=c99 -g ${WARN} ${OPTIMIZE} 7 | CFLAGS += -Wmissing-prototypes 8 | CFLAGS += -Wstrict-prototypes 9 | CFLAGS += -Wmissing-declarations 10 | 11 | # If libtheft is available, build additional property-based tests. 12 | # Uncomment these to use it in test_heatshrink_dynamic. 13 | #CFLAGS += -DHEATSHRINK_HAS_THEFT 14 | #LDFLAGS += -ltheft 15 | 16 | all: 17 | @echo "For tests, make test_heatshrink_dynamic (default) or change the" 18 | @echo "config.h to disable static memory and build test_heatshrink_static." 19 | @echo "For the standalone command-line tool, make heatshrink." 20 | 21 | ${PROJECT}: heatshrink.c 22 | 23 | OBJS= heatshrink_encoder.o \ 24 | heatshrink_decoder.o \ 25 | 26 | heatshrink: ${OBJS} 27 | test_heatshrink_dynamic: ${OBJS} test_heatshrink_dynamic_theft.o 28 | test_heatshrink_static: ${OBJS} 29 | 30 | *.o: Makefile heatshrink_config.h 31 | 32 | heatshrink_decoder.o: heatshrink_decoder.h heatshrink_common.h 33 | heatshrink_encoder.o: heatshrink_encoder.h heatshrink_common.h 34 | 35 | tags: TAGS 36 | 37 | TAGS: 38 | etags *.[ch] 39 | 40 | diagrams: dec_sm.png enc_sm.png 41 | 42 | dec_sm.png: dec_sm.dot 43 | dot -o $@ -Tpng $< 44 | 45 | enc_sm.png: enc_sm.dot 46 | dot -o $@ -Tpng $< 47 | 48 | clean: 49 | rm -f ${PROJECT} test_heatshrink_{dynamic,static} *.o *.core {dec,enc}_sm.png TAGS 50 | -------------------------------------------------------------------------------- /src/heatshrink/README.md: -------------------------------------------------------------------------------- 1 | # heatshrink 2 | 3 | A data compression/decompression library for embedded/real-time systems. 4 | 5 | ## Key Features: 6 | 7 | - **Low memory usage (as low as 50 bytes)** 8 | It is useful for some cases with less than 50 bytes, and useful 9 | for many general cases with < 300 bytes. 10 | - **Incremental, bounded CPU use** 11 | You can chew on input data in arbitrarily tiny bites. 12 | This is a useful property in hard real-time environments. 13 | - **Can use either static or dynamic memory allocation** 14 | The library doesn't impose any constraints on memory management. 15 | - **ISC license** 16 | You can use it freely, even for commercial purposes. 17 | 18 | ## Getting Started: 19 | 20 | There is a standalone command-line program, `heatshrink`, but the 21 | encoder and decoder can also be used as libraries, independent of each 22 | other. To do so, copy `heatshrink_common.h`, `heatshrink_config.h`, and 23 | either `heatshrink_encoder.c` or `heatshrink_decoder.c` (and their 24 | respective header) into your project. 25 | 26 | Dynamic allocation is used by default, but in an embedded context, you 27 | probably want to statically allocate the encoder/decoder. Set 28 | `HEATSHRINK_DYNAMIC_ALLOC` to 0 in `heatshrink_config.h`. 29 | 30 | ## More Information and Benchmarks: 31 | 32 | heatshrink is based on [LZSS], since it's particularly suitable for 33 | compression in small amounts of memory. It can use an optional, small 34 | [index] to make compression significantly faster, but otherwise can run 35 | in under 100 bytes of memory. The index currently adds 2^(window size+1) 36 | bytes to memory usage for compression, and temporarily allocates 512 37 | bytes on the stack during index construction. 38 | 39 | For more information, see the [blog post] for an overview, and the 40 | `heatshrink_encoder.h` / `heatshrink_decoder.h` header files for API 41 | documentation. 42 | 43 | [blog post]: http://spin.atomicobject.com/2013/03/14/heatshrink-embedded-data-compression/ 44 | [index]: http://spin.atomicobject.com/2014/01/13/lightweight-indexing-for-embedded-systems/ 45 | [LZSS]: http://en.wikipedia.org/wiki/Lempel-Ziv-Storer-Szymanski 46 | 47 | ## Build Status 48 | 49 | [![Build Status](https://travis-ci.org/atomicobject/heatshrink.png)](http://travis-ci.org/atomicobject/heatshrink) 50 | -------------------------------------------------------------------------------- /src/heatshrink/dec_sm.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | graph [label="Decoder state machine", labelloc="t"] 3 | Start [style="invis", shape="point"] 4 | empty 5 | input_available 6 | yield_literal 7 | backref_index_msb 8 | backref_index_lsb 9 | backref_count_msb 10 | backref_count_lsb 11 | yield_backref 12 | check_for_more_input 13 | done [peripheries=2] 14 | 15 | empty->input_available [label="sink()", color="blue", weight=10] 16 | Start->empty 17 | 18 | input_available->yield_literal [label="pop 1-bit"] 19 | input_available->backref_index_msb [label="pop 0-bit", weight=10] 20 | input_available->backref_index_lsb [label="pop 0-bit, index <8 bits", weight=10] 21 | 22 | yield_literal->yield_literal [label="sink()", color="blue"] 23 | yield_literal->yield_literal [label="poll()", color="red"] 24 | yield_literal->check_for_more_input [label="poll(), done", color="red"] 25 | 26 | backref_index_msb->backref_index_msb [label="sink()", color="blue"] 27 | backref_index_msb->backref_index_lsb [label="pop index, upper bits", weight=10] 28 | backref_index_msb->done [label="finish()", color="blue"] 29 | 30 | backref_index_lsb->backref_index_lsb [label="sink()", color="blue"] 31 | backref_index_lsb->backref_count_msb [label="pop index, lower bits", weight=10] 32 | backref_index_lsb->backref_count_lsb [label="pop index, count <=8 bits", weight=10] 33 | backref_index_lsb->done [label="finish()", color="blue"] 34 | 35 | backref_count_msb->backref_count_msb [label="sink()", color="blue"] 36 | backref_count_msb->backref_count_lsb [label="pop count, upper bits", weight=10] 37 | backref_count_msb->done [label="finish()", color="blue"] 38 | 39 | backref_count_lsb->backref_count_lsb [label="sink()", color="blue"] 40 | backref_count_lsb->yield_backref [label="pop count, lower bits", weight=10] 41 | backref_count_lsb->done [label="finish()", color="blue"] 42 | 43 | yield_backref->yield_backref [label="sink()", color="blue"] 44 | yield_backref->yield_backref [label="poll()", color="red"] 45 | yield_backref->check_for_more_input [label="poll(), done", 46 | color="red", weight=10] 47 | 48 | check_for_more_input->empty [label="no"] 49 | check_for_more_input->input_available [label="yes"] 50 | 51 | empty->done [label="finish()", color="blue"] 52 | } 53 | -------------------------------------------------------------------------------- /src/heatshrink/enc_sm.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | graph [label="Encoder state machine", labelloc="t"] 3 | start [style="invis", shape="point"] 4 | not_full 5 | filled 6 | search 7 | yield_tag_bit 8 | yield_literal 9 | yield_br_length 10 | yield_br_index 11 | save_backlog 12 | flush_bits 13 | done [peripheries=2] 14 | 15 | start->not_full [label="start"] 16 | 17 | not_full->not_full [label="sink(), not full", color="blue"] 18 | not_full->filled [label="sink(), buffer is full", color="blue"] 19 | not_full->filled [label="finish(), set is_finished", color="blue"] 20 | 21 | filled->search [label="indexing (if any)"] 22 | 23 | search->search [label="step"] 24 | search->yield_tag_bit [label="literal"] 25 | search->yield_tag_bit [label="match found"] 26 | search->save_backlog [label="input exhausted"] 27 | 28 | yield_tag_bit->yield_tag_bit [label="poll(), full buf", color="red"] 29 | yield_tag_bit->yield_literal [label="poll(), literal", color="red"] 30 | yield_tag_bit->yield_br_index [label="poll(), no literal", color="red"] 31 | yield_tag_bit->flush_bits [label="finishing, no literal"] 32 | 33 | yield_literal->yield_literal [label="poll(), full buf", color="red"] 34 | yield_literal->search [label="poll(), no match", color="red"] 35 | yield_literal->yield_tag_bit [label="poll(), match", color="red"] 36 | yield_literal->flush_bits [label="poll(), final literal", color="red"] 37 | 38 | yield_br_index->yield_br_index [label="poll(), full buf", color="red"] 39 | yield_br_index->yield_br_length [label="poll()", color="red"] 40 | 41 | yield_br_length->yield_br_length [label="poll(), full buf", color="red"] 42 | yield_br_length->search [label="done"] 43 | 44 | save_backlog->flush_bits [label="finishing, no literal"] 45 | save_backlog->yield_tag_bit [label="finishing, literal"] 46 | save_backlog->not_full [label="expect more input"] 47 | 48 | flush_bits->flush_bits [label="poll(), full buf", color="red"] 49 | flush_bits->done [label="poll(), flushed", color="red"] 50 | flush_bits->done [label="no more output"] 51 | } 52 | -------------------------------------------------------------------------------- /src/helpers.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | 7 | #include "espconn.h" 8 | #include "gpio.h" 9 | #include "driver/uart.h" 10 | #include "microrl.h" 11 | #include "console.h" 12 | #include 13 | 14 | static const char *modes[] = { 15 | [0x0] = "NONE", 16 | [STATION_MODE] = "STA", 17 | [SOFTAP_MODE] = "AP", 18 | [STATIONAP_MODE] = "APSTA", 19 | }; 20 | 21 | static const char *ciphers[] = { 22 | [AUTH_OPEN] = "OPEN", 23 | [AUTH_WEP] = "WEP", 24 | [AUTH_WPA_PSK] = "WPA_PSK", 25 | [AUTH_WPA2_PSK] = "WPA2_PSK", 26 | [AUTH_WPA_WPA2_PSK] = "WPA_WPA2_PSK", 27 | }; 28 | 29 | static const char *ifacename[] = { 30 | [STATION_IF] = "sta0", 31 | [SOFTAP_IF] = "ap0", 32 | }; 33 | 34 | static const char *ifacedsc[] = { 35 | [STATION_IF] = "WiFi Client Interface", 36 | [SOFTAP_IF] = "WiFi Access Point Interface", 37 | }; 38 | 39 | 40 | static const char *sta_states[] = { 41 | [STATION_IDLE] = "Idle", 42 | [STATION_CONNECTING] = "Connecting", 43 | [STATION_WRONG_PASSWORD] = "Wrong Password", 44 | [STATION_NO_AP_FOUND] = "No AP Found", 45 | [STATION_CONNECT_FAIL] = "Connection Failed", 46 | [STATION_GOT_IP] = "Connected", 47 | }; 48 | 49 | 50 | int lookup_index(const char* key, const char **tbl, int count) 51 | { 52 | int i; 53 | for (i=0; i= count) 63 | return NULL; 64 | return tbl[key]; 65 | } 66 | 67 | 68 | #define DECLARE_LOOKUP(_table, _func) \ 69 | const char *id_to_ ## _func(int id) \ 70 | { \ 71 | return lookup_string(id, _table, ARRAY_SIZE(_table)); \ 72 | } \ 73 | int id_from_ ## _func(const char *id) \ 74 | { \ 75 | return lookup_index(id, _table, ARRAY_SIZE(_table)); \ 76 | } \ 77 | 78 | 79 | DECLARE_LOOKUP(modes, wireless_mode); 80 | DECLARE_LOOKUP(ciphers, encryption_mode); 81 | DECLARE_LOOKUP(ifacename, iface_name); 82 | DECLARE_LOOKUP(ifacedsc, iface_description); 83 | DECLARE_LOOKUP(sta_states, sta_state); 84 | 85 | #define is_digit(c) ((c) >= '0' && (c) <= '9') 86 | 87 | unsigned long skip_atoul(const char **s) 88 | { 89 | unsigned long i = 0; 90 | 91 | while (is_digit(**s)) 92 | i = i * 10 + *((*s)++) - '0'; 93 | 94 | return i; 95 | } 96 | -------------------------------------------------------------------------------- /src/hostname.c: -------------------------------------------------------------------------------- 1 | #include "lwip/netif.h" 2 | #include "lwip/inet.h" 3 | #include "netif/etharp.h" 4 | #include "lwip/tcp.h" 5 | #include "lwip/ip.h" 6 | #include "lwip/init.h" 7 | #include "ets_sys.h" 8 | #include "os_type.h" 9 | //#include "os.h" 10 | #include "lwip/mem.h" 11 | 12 | #include "lwip/app/espconn_tcp.h" 13 | #include "lwip/app/espconn_udp.h" 14 | #include "lwip/app/espconn.h" 15 | 16 | 17 | void set_dhcp_hostname(char *hname) 18 | { 19 | char name[4] = "if1"; 20 | console_printf(name); 21 | 22 | struct netif *i = netif_find("ew0"); 23 | // i->hostname = hname; 24 | /* LWIP compiled with no hostname support 25 | FUCK! 26 | */ 27 | 28 | for (name[0] = 'a' ; name[0] < 'z' ; name[0]++) 29 | for (name[1] = 'a' ; name[1] < 'z' ; name[1]++) { 30 | i = netif_find(name); 31 | if (i) 32 | console_printf("found: %s\n", name); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/httpd/auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | HTTP auth implementation. Only does basic authentication for now. 3 | */ 4 | 5 | /* 6 | * ---------------------------------------------------------------------------- 7 | * "THE BEER-WARE LICENSE" (Revision 42): 8 | * Jeroen Domburg wrote this file. As long as you retain 9 | * this notice you can do whatever you want with this stuff. If we meet some day, 10 | * and you think this stuff is worth it, you can buy me a beer in return. 11 | * ---------------------------------------------------------------------------- 12 | */ 13 | 14 | 15 | #include 16 | #include 17 | #include 18 | #include "mem.h" 19 | #include "user_interface.h" 20 | #include "httpd.h" 21 | #include "cgi.h" 22 | #include "auth.h" 23 | #include "io.h" 24 | #include "base64.h" 25 | 26 | int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData) { 27 | const char *forbidden="401 Forbidden."; 28 | int no=0; 29 | int r; 30 | char hdr[(AUTH_MAX_USER_LEN+AUTH_MAX_PASS_LEN+2)*10]; 31 | char userpass[AUTH_MAX_USER_LEN+AUTH_MAX_PASS_LEN+2]; 32 | char user[AUTH_MAX_USER_LEN]; 33 | char pass[AUTH_MAX_PASS_LEN]; 34 | if (connData->conn==NULL) { 35 | //Connection aborted. Clean up. 36 | return HTTPD_CGI_DONE; 37 | } 38 | 39 | r=httpdGetHeader(connData, "Authorization", hdr, sizeof(hdr)); 40 | if (r && strncmp(hdr, "Basic", 5)==0) { 41 | r=base64_decode(strlen(hdr)-6, hdr+6, sizeof(userpass), (unsigned char *)userpass); 42 | if (r<0) r=0; //just clean out string on decode error 43 | userpass[r]=0; //zero-terminate user:pass string 44 | // os_printf("Auth: %s\n", userpass); 45 | while (((AuthGetUserPw)(connData->cgiArg))(connData, no, 46 | user, AUTH_MAX_USER_LEN, pass, AUTH_MAX_PASS_LEN)) { 47 | //Check user/pass against auth header 48 | if (strlen(userpass)==strlen(user)+strlen(pass)+1 && 49 | os_strncmp(userpass, user, strlen(user))==0 && 50 | userpass[strlen(user)]==':' && 51 | os_strcmp(userpass+strlen(user)+1, pass)==0) { 52 | //Authenticated. Yay! 53 | return HTTPD_CGI_AUTHENTICATED; 54 | } 55 | no++; //Not authenticated with this user/pass. Check next user/pass combo. 56 | } 57 | } 58 | 59 | //Not authenticated. Go bug user with login screen. 60 | httpdStartResponse(connData, 401); 61 | httpdHeader(connData, "Content-Type", "text/plain"); 62 | httpdHeader(connData, "WWW-Authenticate", "Basic realm=\""HTTP_AUTH_REALM"\""); 63 | httpdEndHeaders(connData); 64 | espconn_sent(connData->conn, (uint8 *)forbidden, os_strlen(forbidden)); 65 | //Okay, all done. 66 | return HTTPD_CGI_DONE; 67 | } 68 | -------------------------------------------------------------------------------- /src/httpd/auth.h: -------------------------------------------------------------------------------- 1 | #ifndef AUTH_H 2 | #define AUTH_H 3 | 4 | #include "httpdconfig.h" 5 | 6 | #ifndef HTTP_AUTH_REALM 7 | #define HTTP_AUTH_REALM "Protected" 8 | #endif 9 | 10 | #define HTTPD_AUTH_SINGLE 0 11 | #define HTTPD_AUTH_CALLBACK 1 12 | 13 | #define AUTH_MAX_USER_LEN 32 14 | #define AUTH_MAX_PASS_LEN 32 15 | 16 | //Parameter given to authWhatever functions. This callback returns the usernames/passwords the device 17 | //has. 18 | typedef int (* AuthGetUserPw)(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen); 19 | 20 | int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData); 21 | 22 | #endif -------------------------------------------------------------------------------- /src/httpd/base64.h: -------------------------------------------------------------------------------- 1 | int base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out); 2 | -------------------------------------------------------------------------------- /src/httpd/cgi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGI_H 2 | #define CGI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiLed(HttpdConnData *connData); 7 | void tplLed(HttpdConnData *connData, char *token, void **arg); 8 | int cgiReadFlash(HttpdConnData *connData); 9 | void tplCounter(HttpdConnData *connData, char *token, void **arg); 10 | void tplAction(HttpdConnData *connData, char *token, void **arg); 11 | int cgiShowInputs(HttpdConnData *connData); 12 | void tplStatus(HttpdConnData *connData, char *token, void **arg); 13 | 14 | #endif -------------------------------------------------------------------------------- /src/httpd/cgiwifi.h: -------------------------------------------------------------------------------- 1 | #ifndef CGIWIFI_H 2 | #define CGIWIFI_H 3 | 4 | #include "httpd.h" 5 | 6 | int cgiWiFiScan(HttpdConnData *connData); 7 | void tplWlan(HttpdConnData *connData, char *token, void **arg); 8 | int cgiWiFi(HttpdConnData *connData); 9 | int cgiWiFiConnect(HttpdConnData *connData); 10 | int cgiWifiSetMode(HttpdConnData *connData); 11 | 12 | #endif -------------------------------------------------------------------------------- /src/httpd/config_store.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 2 | * This file is part of the atproto AT protocol library 3 | * 4 | * Redistribution and use is permitted according to the conditions of the 5 | * 3-clause BSD license to be found in the LICENSE file. 6 | */ 7 | 8 | // #include "dce_common.h" 9 | // #include "dce_private.h" 10 | #include "c_types.h" 11 | #include "spi_flash.h" 12 | #include "config_store.h" 13 | #include "user_interface.h" 14 | #include "ets_sys.h" 15 | 16 | #define CONFIG_START_SECTOR 0x3C 17 | #define CONFIG_SECTOR (CONFIG_START_SECTOR + 0) 18 | #define CONFIG_ADDR (SPI_FLASH_SEC_SIZE * CONFIG_SECTOR) 19 | 20 | #define CONFIG_WIFI_SECTOR 0x7E 21 | 22 | static config_t s_config; 23 | static int s_config_loaded = 0; 24 | 25 | void ICACHE_FLASH_ATTR config_read(config_t* config) 26 | { 27 | spi_flash_read(CONFIG_ADDR, (uint32*) config, sizeof(config_t)); 28 | } 29 | 30 | void ICACHE_FLASH_ATTR config_write(config_t* config) 31 | { 32 | ETS_UART_INTR_DISABLE(); 33 | spi_flash_erase_sector(CONFIG_SECTOR); 34 | spi_flash_write(CONFIG_ADDR, (uint32*) config, sizeof(config_t)); 35 | ETS_UART_INTR_ENABLE(); 36 | } 37 | 38 | config_t* ICACHE_FLASH_ATTR config_get() 39 | { 40 | if (!s_config_loaded) 41 | { 42 | config_read(&s_config); 43 | s_config_loaded = 1; 44 | } 45 | return &s_config; 46 | } 47 | 48 | void ICACHE_FLASH_ATTR config_save() 49 | { 50 | config_write(&s_config); 51 | config_t tmp; 52 | config_read(&tmp); 53 | if (memcmp(&tmp, &s_config, sizeof(config_t)) != 0) 54 | { 55 | // DCE_FAIL("config verify failed"); 56 | } 57 | } 58 | 59 | config_t* ICACHE_FLASH_ATTR config_init() 60 | { 61 | config_t* config = config_get(); 62 | if (config->magic != CONFIG_MAGIC || config->version != CONFIG_VERSION) 63 | { 64 | config_init_default(); 65 | } 66 | return config; 67 | } 68 | 69 | void ICACHE_FLASH_ATTR config_init_default() 70 | { 71 | config_t* config = config_get(); 72 | config->magic = CONFIG_MAGIC; 73 | config->version = CONFIG_VERSION; 74 | config->baud_rate = 9600; 75 | config_save(); 76 | 77 | ETS_UART_INTR_DISABLE(); 78 | spi_flash_erase_sector(CONFIG_WIFI_SECTOR); 79 | ETS_UART_INTR_ENABLE(); 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/httpd/config_store.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 2 | * This file is part of the atproto AT protocol library 3 | * 4 | * Redistribution and use is permitted according to the conditions of the 5 | * 3-clause BSD license to be found in the LICENSE file. 6 | */ 7 | 8 | #ifndef CONFIG_STORE_H 9 | #define CONFIG_STORE_H 10 | 11 | #define CONFIG_MAGIC 0x42 12 | #define CONFIG_VERSION 1 13 | 14 | #include 15 | 16 | typedef struct { 17 | int32_t magic; 18 | int32_t version; 19 | int32_t baud_rate; 20 | // bump CONFIG_VERSION when adding new fields 21 | } config_t; 22 | 23 | 24 | config_t* config_get(); 25 | void config_save(); 26 | config_t* config_init(); 27 | void config_init_default(); 28 | 29 | #endif//CONFIG_STORE_H 30 | -------------------------------------------------------------------------------- /src/httpd/espfs.h: -------------------------------------------------------------------------------- 1 | #ifndef ESPFS_H 2 | #define ESPFS_H 3 | 4 | 5 | 6 | typedef struct EspFsFile EspFsFile; 7 | 8 | EspFsFile *espFsOpen(char *fileName); 9 | int espFsRead(EspFsFile *fh, char *buff, int len); 10 | void espFsClose(EspFsFile *fh); 11 | 12 | 13 | #endif -------------------------------------------------------------------------------- /src/httpd/heatshrink_config_httpd.h: -------------------------------------------------------------------------------- 1 | //Heatshrink config for the decompressor. 2 | #ifndef HEATSHRINK_CONFIG_H 3 | #define HEATSHRINK_CONFIG_H 4 | 5 | /* Should functionality assuming dynamic allocation be used? */ 6 | #define HEATSHRINK_DYNAMIC_ALLOC 1 7 | 8 | #if HEATSHRINK_DYNAMIC_ALLOC 9 | /* Optional replacement of malloc/free */ 10 | #define HEATSHRINK_MALLOC(SZ) os_malloc(SZ) 11 | #define HEATSHRINK_FREE(P, SZ) os_free(P) 12 | #else 13 | /* Required parameters for static configuration */ 14 | #define HEATSHRINK_STATIC_INPUT_BUFFER_SIZE 32 15 | #define HEATSHRINK_STATIC_WINDOW_BITS 8 16 | #define HEATSHRINK_STATIC_LOOKAHEAD_BITS 4 17 | #endif 18 | 19 | /* Turn on logging for debugging. */ 20 | #define HEATSHRINK_DEBUGGING_LOGS 0 21 | 22 | /* Use indexing for faster compression. (This requires additional space.) */ 23 | #define HEATSHRINK_USE_INDEX 1 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /src/httpd/heatshrink_decoder.c: -------------------------------------------------------------------------------- 1 | #include "httpdconfig.h" 2 | #ifdef EFS_HEATSHRINK 3 | //Stupid wrapper so we don't have to move c-files around 4 | //Also loads httpd-specific config. 5 | 6 | #include 7 | #define _STDLIB_H_ 8 | #define _STRING_H_ 9 | #define _STDDEF_H 10 | #define _STDINT_H 11 | 12 | #include "c_types.h" 13 | #include "mem.h" 14 | #include "osapi.h" 15 | #include "heatshrink_config_httpd.h" 16 | #define memset(x,y,z) os_memset(x,y,z) 17 | #define memcpy(x,y,z) os_memcpy(x,y,z) 18 | #include "../heatshrink/heatshrink_decoder.c" 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/httpd/httpd.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPD_H 2 | #define HTTPD_H 3 | #include 4 | #include 5 | 6 | #define HTTPDVER "0.2" 7 | 8 | #define HTTPD_CGI_MORE 0 9 | #define HTTPD_CGI_DONE 1 10 | #define HTTPD_CGI_NOTFOUND 2 11 | #define HTTPD_CGI_AUTHENTICATED 2 //for now 12 | 13 | typedef struct HttpdPriv HttpdPriv; 14 | typedef struct HttpdConnData HttpdConnData; 15 | 16 | typedef int (* cgiSendCallback)(HttpdConnData *connData); 17 | 18 | //A struct describing a http connection. This gets passed to cgi functions. 19 | struct HttpdConnData { 20 | struct espconn *conn; 21 | char *url; 22 | char *getArgs; 23 | const void *cgiArg; 24 | void *cgiData; 25 | HttpdPriv *priv; 26 | cgiSendCallback cgi; 27 | int postLen; 28 | char *postBuff; 29 | }; 30 | 31 | //A struct describing an url. This is the main struct that's used to send different URL requests to 32 | //different routines. 33 | typedef struct { 34 | const char *url; 35 | cgiSendCallback cgiCb; 36 | const void *cgiArg; 37 | } HttpdBuiltInUrl; 38 | 39 | int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData); 40 | void ICACHE_FLASH_ATTR httpdRedirect(HttpdConnData *conn, char *newUrl); 41 | int httpdUrlDecode(char *val, int valLen, char *ret, int retLen); 42 | int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen); 43 | void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port); 44 | const char *httpdGetMimetype(char *url); 45 | void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code); 46 | void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val); 47 | void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn); 48 | int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/httpd/httpdespfs.h: -------------------------------------------------------------------------------- 1 | #ifndef HTTPDESPFS_H 2 | #define HTTPDESPFS_H 3 | 4 | #include "httpd.h" 5 | #include "espfs.h" 6 | 7 | int cgiEspFsHook(HttpdConnData *connData); 8 | int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData); 9 | 10 | #endif -------------------------------------------------------------------------------- /src/httpd/io.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * ---------------------------------------------------------------------------- 4 | * "THE BEER-WARE LICENSE" (Revision 42): 5 | * Jeroen Domburg wrote this file. As long as you retain 6 | * this notice you can do whatever you want with this stuff. If we meet some day, 7 | * and you think this stuff is worth it, you can buy me a beer in return. 8 | * ---------------------------------------------------------------------------- 9 | */ 10 | 11 | 12 | #include "espmissingincludes.h" 13 | #include "c_types.h" 14 | #include "user_interface.h" 15 | #include "espconn.h" 16 | #include "mem.h" 17 | #include "osapi.h" 18 | #include "gpio.h" 19 | #include "lwip/sys.h" 20 | 21 | #define LEDGPIO 2 22 | #define BTNGPIO 0 23 | 24 | static ETSTimer resetBtntimer; 25 | static ETSTimer doorOpenDelay; 26 | 27 | void ICACHE_FLASH_ATTR doorOpenDelayCb() { 28 | os_timer_disarm(&doorOpenDelay); 29 | gpio_output_set(0, (1<=6) { //3 sec pressed 46 | wifi_station_disconnect(); 47 | wifi_set_opmode(0x3); //reset to AP+STA mode 48 | os_printf("Reset to AP mode. Restarting system...\n"); 49 | system_restart(); 50 | } 51 | resetCnt=0; 52 | } 53 | } 54 | 55 | void ioInit() { 56 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); 57 | PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); 58 | gpio_output_set(0, 0, (1< 5 | #include 6 | #include 7 | 8 | // #include "Profiles\profiles.h" 9 | 10 | /* 11 | #define GET_SYSEX_DATA (0xFF) 12 | #define RECEIVING_SYSEX_DATA (1) 13 | #define SYSEX_DATA_ERROR (3) 14 | 15 | void SysexSend(void* data, uint16_t len); 16 | uint8_t IsReceivingSysExData(uint8_t state); 17 | void ParseSysExData(uint8_t nextByte); 18 | void SysExFlush(void); 19 | void SysEx_ReceiveError(void); 20 | */ 21 | 22 | 23 | 24 | 25 | void serialWrite(char c); 26 | void startSysex(void); 27 | void endSysex(void); 28 | void sendValueAsTwo7bitBytes(int value); 29 | void sendSysex(int command, int bytec, char* bytev); 30 | void SysexProcessInput(char c); 31 | void sysexCallback(char command, char argc, char* argv); 32 | 33 | typedef void (*sysex_callback_fn_t)(char command, int length, int); 34 | 35 | 36 | #define START_SYSEX 0xF0 // start a MIDI Sysex message 37 | #define END_SYSEX 0xF7 // end a MIDI Sysex message 38 | #define SYSTEM_RESET 0xFF // reset from MIDI 39 | #define SET_PIN_MODE 0xF4 40 | #define SET_PIN 0x32 41 | #define SEND_INT_VAL 0x33 42 | #define COMMAND_NOT_FOUND 0x34 43 | #define COMMAND_OK 0x35 44 | #define L_SET_PIN_MODE 0x36 45 | #define L_SET_PIN 0x37 46 | #define DEBUG_PIN_VALUE 0x39 47 | #define L_DEBUG_PIN_VALUE 0x3A 48 | #define SEND_KEEPALIVE 0x3B 49 | #define SET_ENCODER_VALUE 0x40 50 | #define GET_ENCODER_VALUE 0x41 51 | #define ENABLE_DEBUG_PIN_VALUE 0x42 52 | #define DISABLE_DEBUG_PIN_VALUE 0x43 53 | #define L_ENABLE_DEBUG_PIN_VALUE 0x44 54 | #define L_DISABLE_DEBUG_PIN_VALUE 0x45 55 | #define SEND_ALL_INPUTS 0x46 56 | #define UART_CONNECTED 0x47 57 | 58 | 59 | #define MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages 60 | 61 | // encoders 62 | #define ENCODER_01 0x01 63 | #define ENCODER_02 0x02 64 | #define ENCODER_03 0x03 65 | #define ENCODER_04 0x04 66 | #define ENCODER_05 0x05 67 | 68 | #define INPUT_COUNT 16 69 | #define ENCODER_COUNT 5 70 | 71 | struct encoder 72 | { 73 | int id; 74 | char* label; 75 | int value; 76 | } encoder_t; 77 | 78 | struct encoder Inputs[INPUT_COUNT]; 79 | struct encoder Encoders[ENCODER_COUNT]; 80 | 81 | 82 | #endif 83 | 84 | -------------------------------------------------------------------------------- /src/httpd/uart.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 2 | * This file is part of the atproto AT protocol library 3 | * 4 | * Redistribution and use is permitted according to the conditions of the 5 | * 3-clause BSD license to be found in the LICENSE file. 6 | */ 7 | 8 | #ifndef ESP8266_UART_H 9 | #define ESP8266_UART_H 10 | 11 | #define UART_RX_BUFFER_SIZE 1024 12 | #define UART_TX_BUFFER_SIZE 1024 13 | 14 | typedef void (*uart_rx_handler_t)(char); 15 | 16 | typedef struct _uart uart_t; 17 | 18 | uart_t* uart0_init(int baud_rate, uart_rx_handler_t rx_handler); 19 | void uart0_set_baudrate(uart_t* uart, int baud_rate); 20 | int uart0_get_baudrate(uart_t* uart); 21 | void uart0_uninit(uart_t* uart); 22 | void uart0_transmit(uart_t* uart, const char* buf, int size); // may block on TX fifo 23 | void uart0_wait_for_transmit(uart_t* uart); 24 | void uart0_transmit_char(uart_t* uart, char c); // does not block, but character will be lost if FIFO is full 25 | 26 | void uart_set_debug(int enabled); 27 | int uart_get_debug(); 28 | #endif//ESP8266_UART_H -------------------------------------------------------------------------------- /src/i2c_at24eep.c: -------------------------------------------------------------------------------- 1 | #include "c_types.h" 2 | #include "ets_sys.h" 3 | #include "osapi.h" 4 | #include "console.h" 5 | 6 | #include "driver/i2c_master.h" 7 | #include "driver/i2c_at24eep.h" 8 | 9 | #ifdef CONFIG_CMD_AT24EEP_DEBUG 10 | #define dbg(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 11 | #else 12 | #define dbg(fmt, ...) 13 | #endif 14 | 15 | bool AT24EEP_Write(/*uint8 address, uint8 length, uint8 *values*/) 16 | { 17 | //TODO push address to values head 18 | //return i2c_master_writeBytes(AT24EEP_ADDRESS, values, length+1); 19 | return true; 20 | } 21 | 22 | bool AT24EEP_Read(/*uint8 address, uint8 length, uint8 *values*/) 23 | { 24 | //TODO push address to values head 25 | //return i2c_master_readBytes(AT24EEP_ADDRESS, values, length+1); 26 | return true; 27 | } 28 | 29 | bool AT24EEP_Init() 30 | { 31 | //TODO detect flash size by reading max address 32 | uint8 addr = 0x80; 33 | uint8 temp; 34 | while(i2c_master_readUint8(AT24EEP_ADDRESS, addr, &temp)){ 35 | console_printf( "Addr 0x%02x == %d \n", addr, temp); 36 | addr *= 2; 37 | } 38 | console_printf( "Failed to read addr 0x%02x\n", addr); 39 | 40 | IS_ALREADY_INITED = true; 41 | return true; 42 | } 43 | 44 | static int do_i2c_at24eep(int argc, const char* const* argv) 45 | { 46 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 47 | 48 | if(!IS_ALREADY_INITED && !AT24EEP_Init()){ 49 | console_printf( "Failed\n" ); 50 | return 0; 51 | } 52 | 53 | if(AT24EEP_Read()){ 54 | //console_printf( argc == 1 ? "%d\n" : "Light: %d lux\n", LAST_BH_LIGHT); 55 | }else{ 56 | console_printf( "Failed to read value\n" ); 57 | } 58 | 59 | } else 60 | 61 | if(strcmp(argv[1], "write") == 0){ 62 | 63 | if(AT24EEP_Write()){ 64 | }else{ 65 | console_printf( "Failed to write value\n" ); 66 | } 67 | 68 | } else 69 | 70 | if(strcmp(argv[1], "init") == 0){ 71 | 72 | console_printf( AT24EEP_Init() ? "Ok\n":"Failed\n" ); 73 | } 74 | 75 | return 0; 76 | } 77 | 78 | CONSOLE_CMD(i2c_at24eep, 0, 2, 79 | do_i2c_at24eep, NULL, NULL, 80 | "I2C EEPROM serial memory" 81 | HELPSTR_NEWLINE "i2c_at24eep init" 82 | HELPSTR_NEWLINE "i2c_at24eep [read]" 83 | ); 84 | -------------------------------------------------------------------------------- /src/i2c_bh1750.c: -------------------------------------------------------------------------------- 1 | #include "c_types.h" 2 | #include "ets_sys.h" 3 | #include "osapi.h" 4 | #include "console.h" 5 | 6 | #include "driver/i2c_master.h" 7 | #include "driver/i2c_bh1750.h" 8 | 9 | #ifdef CONFIG_CMD_BH1750_DEBUG 10 | #define dbg(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 11 | #else 12 | #define dbg(fmt, ...) 13 | #endif 14 | 15 | static uint8 currentmode = BH1750_ONE_TIME_HIGH_RES_MODE; 16 | 17 | bool BH1750_Read() 18 | { 19 | if(!i2c_master_writeBytes1(BH1750_ADDRESS, currentmode)){ 20 | return false; 21 | } 22 | 23 | os_delay_us(BH1750_CONVERSION_TIME*1000); 24 | 25 | uint16 light; 26 | if(i2c_master_readUint16(BH1750_ADDRESS, 0, &light)){ 27 | LAST_BH_LIGHT = (light - 256) / 1.2; 28 | return true; 29 | } 30 | return false; 31 | } 32 | 33 | 34 | bool BH1750_Init(uint8 mode) 35 | { 36 | if(!i2c_master_writeBytes1(BH1750_ADDRESS, mode)){ 37 | return false; 38 | } 39 | 40 | currentmode = mode; 41 | IS_ALREADY_INITED = true; 42 | return true; 43 | } 44 | 45 | static int do_i2c_bh1750(int argc, const char* const* argv) 46 | { 47 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 48 | 49 | if((IS_ALREADY_INITED || BH1750_Init(BH1750_ONE_TIME_HIGH_RES_MODE)) && BH1750_Read()){ 50 | console_printf( argc == 1 ? "%d\n" : "Light: %d lux\n", LAST_BH_LIGHT); 51 | }else{ 52 | console_printf( "Failed to read value\n" ); 53 | } 54 | } else 55 | 56 | if(strcmp(argv[1], "init") == 0){ 57 | 58 | console_printf( BH1750_Init(BH1750_ONE_TIME_HIGH_RES_MODE) ? "Ok\n":"Failed\n" ); 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | CONSOLE_CMD(i2c_bh1750, 0, 2, 65 | do_i2c_bh1750, NULL, NULL, 66 | "I2C light sensor BH1750" 67 | HELPSTR_NEWLINE "i2c_bh1750 init" 68 | HELPSTR_NEWLINE "i2c_bh1750 [read]" 69 | ); 70 | -------------------------------------------------------------------------------- /src/i2c_ina219.c: -------------------------------------------------------------------------------- 1 | #include "driver/i2c_master.h" 2 | #include "driver/i2c_ina219.h" 3 | #include "console.h" 4 | 5 | bool INA219_writereg16(uint8 reg, uint16 data) 6 | { 7 | return i2c_master_writeBytes3(INA219_ADDRESS, reg, data, data >> 8); 8 | } 9 | 10 | bool INA219_Init() 11 | { 12 | if (INA219_writereg16(INA219_REG_CALIBRATION, INA219_CALIBRATION_VALUE)){ 13 | 14 | IS_ALREADY_INITED = true; 15 | return 1; 16 | } 17 | return 0; 18 | } 19 | 20 | bool INA219_Read() 21 | { 22 | if (!INA219_writereg16(INA219_REG_CONFIG, (INA219_CONFIG_VALUE | INA219_MODE_SHUNT_BUS_TRIG))) 23 | return 0; 24 | 25 | i2c_master_readUint16(INA219_ADDRESS, INA219_REG_BUSVOLTAGE, &LAST_INA219_VOLTAGE); 26 | LAST_INA219_VOLTAGE = (LAST_INA219_VOLTAGE >> 3) * 4; 27 | 28 | i2c_master_readUint16(INA219_ADDRESS, INA219_REG_CURRENT, &LAST_INA219_CURRENT); 29 | if (((LAST_INA219_CURRENT) >> (15)) & 0x01) { //nagative 30 | LAST_INA219_CURRENT = 0; 31 | LAST_INA219_SHUNT_VOLTAGE = 0; 32 | LAST_INA219_POWER = 0; 33 | } else { 34 | LAST_INA219_CURRENT = LAST_INA219_CURRENT / 100; 35 | 36 | i2c_master_readUint16(INA219_ADDRESS, INA219_REG_SHUNTVOLTAGE, &LAST_INA219_SHUNT_VOLTAGE); 37 | LAST_INA219_SHUNT_VOLTAGE /= 1000; 38 | 39 | i2c_master_readUint16(INA219_ADDRESS, INA219_REG_POWER, &LAST_INA219_POWER); 40 | LAST_INA219_POWER /= 5; 41 | } 42 | 43 | if (!INA219_writereg16(INA219_REG_CONFIG, (INA219_CONFIG_VALUE | INA219_MODE_POWER_DOWN))) 44 | return 0; 45 | 46 | return 1; 47 | } 48 | 49 | static int do_i2c_ina219(int argc, const char* const* argv) 50 | { 51 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 52 | 53 | if((IS_ALREADY_INITED || INA219_Init()) && INA219_Read()){ 54 | console_printf( argc == 1 ? "%d %d %d %d\n" : "Voltage: %d\nCurrent: %d\nShuntV: %d\nPower: %d\n", 55 | LAST_INA219_VOLTAGE, LAST_INA219_CURRENT, LAST_INA219_SHUNT_VOLTAGE, LAST_INA219_POWER); 56 | }else{ 57 | console_printf( "Failed to read value\n" ); 58 | } 59 | } else 60 | 61 | if(strcmp(argv[1], "init") == 0){ 62 | 63 | console_printf( INA219_Init() ? "Ok\n":"Failed\n" ); 64 | } 65 | 66 | return 0; 67 | } 68 | 69 | CONSOLE_CMD(i2c_ina219, 0, 2, 70 | do_i2c_ina219, NULL, NULL, 71 | "I2C current sensor INA219" 72 | HELPSTR_NEWLINE "i2c_ina219 init" 73 | HELPSTR_NEWLINE "i2c_ina219 [read]" 74 | ); 75 | -------------------------------------------------------------------------------- /src/i2c_mlx90614.c: -------------------------------------------------------------------------------- 1 | #include "c_types.h" 2 | #include "ets_sys.h" 3 | #include "osapi.h" 4 | #include "console.h" 5 | 6 | #include "driver/i2c_master.h" 7 | #include "driver/i2c_mlx90614.h" 8 | 9 | #ifdef CONFIG_CMD_MLX90614_DEBUG 10 | #define dbg(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 11 | #else 12 | #define dbg(fmt, ...) 13 | #endif 14 | 15 | #ifdef CONFIG_USEFLOAT 16 | float MLX90614_ReadTempFrom(uint8 reg) 17 | { 18 | float result = i2c_master_readRegister16(MLX90614_ADDRESS, reg); 19 | return ((result / 50) - 273.15); 20 | } 21 | #else 22 | sint16 MLX90614_ReadTempFrom(uint8 reg) 23 | { 24 | 25 | uint8 data[3]; 26 | data[0] = reg; 27 | if(i2c_master_readBytes(MLX90614_ADDRESS, data, 3)){ 28 | uint16 temp = (data[1] << 8) | data[0]; 29 | return ((temp / 50.0) - 273.15)*100; 30 | } 31 | return 0; 32 | } 33 | #endif 34 | 35 | bool MLX90614_Read() 36 | { 37 | LAST_MLX90614_AMBIENT_TEMPERATURE = MLX90614_ReadTempFrom(MLX90614_TA); 38 | LAST_MLX90614_OBJECT_TEMPERATURE = MLX90614_ReadTempFrom(MLX90614_TOBJ1); 39 | return true; 40 | } 41 | 42 | 43 | bool MLX90614_Init() 44 | { 45 | #ifdef CONFIG_CMD_MLX90614_DEBUG 46 | console_printf("Sensor ID: %02x %02x %02x %02x\n", 47 | i2c_master_readRegister8(MLX90614_ADDRESS, MLX90614_ID1), 48 | i2c_master_readRegister8(MLX90614_ADDRESS, MLX90614_ID2), 49 | i2c_master_readRegister8(MLX90614_ADDRESS, MLX90614_ID3), 50 | i2c_master_readRegister8(MLX90614_ADDRESS, MLX90614_ID4) 51 | ); 52 | #endif 53 | 54 | IS_ALREADY_INITED = true; 55 | return true; 56 | } 57 | 58 | static int do_i2c_mlx90614(int argc, const char* const* argv) 59 | { 60 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 61 | 62 | if((IS_ALREADY_INITED || MLX90614_Init()) && MLX90614_Read()){ 63 | console_printf( argc == 1 ? "%d %d\n" : "Ambient: %d C\nObject: %d C\n", 64 | #ifdef CONFIG_USEFLOAT 65 | (int)(LAST_MLX90614_AMBIENT_TEMPERATURE*100), 66 | (int)(LAST_MLX90614_OBJECT_TEMPERATURE*100) 67 | #else 68 | LAST_MLX90614_AMBIENT_TEMPERATURE, 69 | LAST_MLX90614_OBJECT_TEMPERATURE 70 | #endif 71 | ); 72 | }else{ 73 | console_printf( "Failed to read value\n" ); 74 | } 75 | } else 76 | 77 | if(strcmp(argv[1], "init") == 0){ 78 | 79 | console_printf( MLX90614_Init() ? "Ok\n":"Failed\n" ); 80 | } 81 | 82 | return 0; 83 | } 84 | 85 | CONSOLE_CMD(i2c_mlx90614, 0, 2, 86 | do_i2c_mlx90614, NULL, NULL, 87 | "I2C non-contact thermopile sensor" 88 | HELPSTR_NEWLINE "i2c_mlx90614 init" 89 | HELPSTR_NEWLINE "i2c_mlx90614 [read]" 90 | ); 91 | -------------------------------------------------------------------------------- /src/i2c_pcf8591.c: -------------------------------------------------------------------------------- 1 | #include "c_types.h" 2 | #include "ets_sys.h" 3 | #include "osapi.h" 4 | #include "console.h" 5 | 6 | #include "driver/i2c_master.h" 7 | #include "driver/i2c_pcf8591.h" 8 | 9 | #ifdef CONFIG_CMD_PCF8591_DEBUG 10 | #define dbg(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 11 | #else 12 | #define dbg(fmt, ...) 13 | #endif 14 | 15 | bool PCF8591_Read() 16 | { 17 | for(uint8 i = 0; i < 4; i++){ 18 | i2c_master_readUint8(PCF8591_ADDRESS, i, &LAST_PCF8591_A[i]); 19 | } 20 | return true; 21 | } 22 | 23 | bool PCF8591_Write(uint8 value) 24 | { 25 | return i2c_master_writeBytes2(PCF8591_ADDRESS, PCF8591_REG_DAC, value); 26 | } 27 | 28 | 29 | bool PCF8591_Init() 30 | { 31 | //TODO: configure for differential input 32 | if(PCF8591_Read()){ 33 | IS_ALREADY_INITED = true; 34 | return true; 35 | } 36 | return false; 37 | } 38 | 39 | static int do_i2c_pcf8591(int argc, const char* const* argv) 40 | { 41 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 42 | 43 | if((IS_ALREADY_INITED || PCF8591_Init()) && PCF8591_Read()){ 44 | if(argc != 1){ 45 | console_printf( "A0-A3: " ); 46 | } 47 | console_printf( "%d %d %d %d\n", LAST_PCF8591_A[0], LAST_PCF8591_A[1], LAST_PCF8591_A[2], LAST_PCF8591_A[3]); 48 | }else{ 49 | console_printf( "Failed to read value\n" ); 50 | } 51 | } else 52 | 53 | if(strcmp(argv[1], "write") == 0){ 54 | 55 | if( argc < 3 ){ 56 | console_printf( "Value not specified\n" ); 57 | return 0; 58 | } 59 | 60 | console_printf(PCF8591_Write(atoi(argv[2]))?"Ok":"Failed to write value"); 61 | 62 | } else 63 | 64 | if(strcmp(argv[1], "init") == 0){ 65 | 66 | console_printf( PCF8591_Init() ? "Ok\n":"Failed\n" ); 67 | } 68 | 69 | return 0; 70 | } 71 | 72 | CONSOLE_CMD(i2c_pcf8591, 0, 3, 73 | do_i2c_pcf8591, NULL, NULL, 74 | "I2C 8-bit ADC DAC PCF8591" 75 | HELPSTR_NEWLINE "i2c_pcf8591 init" 76 | HELPSTR_NEWLINE "i2c_pcf8591 [read]" 77 | HELPSTR_NEWLINE "i2c_pcf8591 write " 78 | ); 79 | -------------------------------------------------------------------------------- /src/i2c_sht21.c: -------------------------------------------------------------------------------- 1 | #include "driver/i2c_master.h" 2 | #include "driver/i2c_sht21.h" 3 | #include "console.h" 4 | 5 | #ifdef CONFIG_CMD_SHT21_DEBUG 6 | #define dbg(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__) 7 | #else 8 | #define dbg(fmt, ...) 9 | #endif 10 | 11 | bool SHT21_Init() 12 | { 13 | 14 | if(i2c_master_writeBytes1(SHT21_ADDRESS, SHT21_SOFT_RESET)) 15 | { 16 | // The soft reset takes less than 15ms. 17 | os_delay_us(SHT21_SOFT_RESET_TIME*1000); 18 | IS_ALREADY_INITED = true; 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | bool SHT21_Read() 25 | { 26 | #ifdef CONFIG_USEFLOAT 27 | #define PRECISION_MULTI 1.0 28 | float temp; 29 | #else 30 | #define PRECISION_MULTI 100 31 | uint16 temp; 32 | #endif 33 | 34 | if(i2c_master_readUint16(SHT21_ADDRESS, SHT21_TRIGGER_TEMP_MEASURE_NOHOLD, &temp)){ 35 | LAST_SHT_TEMPERATURE = (-46.85 + 175.72 / 65536.0 * (temp & ~3)) * PRECISION_MULTI; 36 | } else return false; 37 | 38 | if(i2c_master_readUint16(SHT21_ADDRESS, SHT21_TRIGGER_HUMD_MEASURE_NOHOLD, &temp)){ 39 | LAST_SHT_HUMIDITY = (-6.0 + 125.0 / 65536.0 * (temp & ~3)) * PRECISION_MULTI; 40 | } else return false; 41 | 42 | //TODO read data in hold mode 43 | //LAST_SHT_TEMPERATURE = i2c_master_readRegister16(SHT21_ADDRESS, SHT21_TRIGGER_TEMP_MEASURE_HOLD) & ~3; 44 | //LAST_SHT_HUMIDITY = i2c_master_readRegister16(SHT21_ADDRESS, SHT21_TRIGGER_TEMP_MEASURE_NOHOLD) & ~3; 45 | 46 | return true; 47 | } 48 | 49 | static int do_i2c_sht21(int argc, const char* const* argv) 50 | { 51 | if(argc == 1 || strcmp(argv[1], "read") == 0){ 52 | 53 | if((IS_ALREADY_INITED || SHT21_Init()) && SHT21_Read()){ 54 | console_printf( argc == 1 ? "%d %d\n" : "Temperature: %d C\nHumidity: %d %%\n", 55 | #ifdef CONFIG_USEFLOAT 56 | (int)(LAST_SHT_TEMPERATURE*100), 57 | (int)(LAST_SHT_HUMIDITY*100) 58 | #else 59 | LAST_SHT_TEMPERATURE, 60 | LAST_SHT_HUMIDITY 61 | #endif 62 | ); 63 | }else{ 64 | console_printf( "Failed to read value\n" ); 65 | } 66 | } else 67 | 68 | if(strcmp(argv[1], "init") == 0){ 69 | 70 | console_printf( SHT21_Init() ? "Ok\n":"Failed\n" ); 71 | } 72 | 73 | return 0; 74 | } 75 | 76 | CONSOLE_CMD(i2c_sht21, 0, 2, 77 | do_i2c_sht21, NULL, NULL, 78 | "I2C humidity sensor SHT21" 79 | HELPSTR_NEWLINE "i2c_sht21 init" 80 | HELPSTR_NEWLINE "i2c_sht21 [read]" 81 | ); 82 | -------------------------------------------------------------------------------- /src/iwconnect.c: -------------------------------------------------------------------------------- 1 | #include "ets_sys.h" 2 | #include "os_type.h" 3 | #include "mem.h" 4 | #include "osapi.h" 5 | #include "user_interface.h" 6 | #include "espconn.h" 7 | #include "helpers.h" 8 | #include "iwconnect.h" 9 | #include "env.h" 10 | #include "main.h" 11 | 12 | static int conntimes = 0; 13 | static /*volatile*/ os_timer_t conn_checker; 14 | static void conn_checker_handler(void *arg) 15 | { 16 | int state = wifi_station_get_connect_status(); 17 | switch (state) { 18 | case STATION_CONNECT_FAIL: 19 | console_printf("Failed\n"); 20 | goto bailout; 21 | case STATION_NO_AP_FOUND: 22 | console_printf("NotFound\n"); 23 | goto bailout; 24 | case STATION_GOT_IP: 25 | console_printf("Connected\n"); 26 | goto bailout; 27 | } 28 | 29 | conntimes++; 30 | if (conntimes > 20) { 31 | console_printf("Timeout, still trying\n"); 32 | goto bailout; 33 | } 34 | 35 | return; 36 | bailout: 37 | os_timer_disarm(&conn_checker); 38 | console_lock(0); 39 | return; 40 | } 41 | 42 | int exec_iwconnect(const char *ssid, const char *password) 43 | { 44 | struct station_config sta_conf; 45 | os_strncpy((char*)sta_conf.ssid, ssid, sizeof sta_conf.ssid); 46 | 47 | sta_conf.password[0] = 0x0; 48 | if (password != NULL) { 49 | os_strncpy((char*)&sta_conf.password, password, 32); 50 | } 51 | 52 | wifi_station_disconnect(); 53 | wifi_station_set_config(&sta_conf); 54 | wifi_station_set_hostname(env_get("hostname")); 55 | wifi_station_connect(); 56 | 57 | os_timer_disarm(&conn_checker); 58 | os_timer_setfn(&conn_checker, (os_timer_func_t *)conn_checker_handler, NULL); 59 | os_timer_arm(&conn_checker, 300, 1); 60 | conntimes = 0; 61 | console_lock(1); 62 | 63 | return 0; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/lwip-app/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=dhcpserver.o # This includes stubs if $(CONFIG_SERVICE_DHCPS)==n 2 | objects-y+=espconn.o 3 | objects-y+=espconn_tcp.o 4 | objects-y+=espconn_udp.o 5 | #objects-y+=netio.o 6 | #objects-y+=ping.o 7 | -------------------------------------------------------------------------------- /src/lwip-esp/Makefile: -------------------------------------------------------------------------------- 1 | subdirs-y += api core netif 2 | -------------------------------------------------------------------------------- /src/lwip-esp/api/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=api_lib.o 2 | objects-y+=api_msg.o 3 | objects-y+=err.o 4 | objects-y+=netbuf.o 5 | objects-y+=netdb.o 6 | objects-y+=netifapi.o 7 | objects-y+=sockets.o 8 | objects-y+=tcpip.o 9 | -------------------------------------------------------------------------------- /src/lwip-esp/api/err.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Error Management module 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/err.h" 40 | 41 | #ifdef LWIP_DEBUG 42 | 43 | static const char *err_strerr[] = { 44 | "Ok.", /* ERR_OK 0 */ 45 | "Out of memory error.", /* ERR_MEM -1 */ 46 | "Buffer error.", /* ERR_BUF -2 */ 47 | "Timeout.", /* ERR_TIMEOUT -3 */ 48 | "Routing problem.", /* ERR_RTE -4 */ 49 | "Operation in progress.", /* ERR_INPROGRESS -5 */ 50 | "Illegal value.", /* ERR_VAL -6 */ 51 | "Operation would block.", /* ERR_WOULDBLOCK -7 */ 52 | "Connection aborted.", /* ERR_ABRT -8 */ 53 | "Connection reset.", /* ERR_RST -9 */ 54 | "Connection closed.", /* ERR_CLSD -10 */ 55 | "Not connected.", /* ERR_CONN -11 */ 56 | "Illegal argument.", /* ERR_ARG -12 */ 57 | "Address in use.", /* ERR_USE -13 */ 58 | "Low-level netif error.", /* ERR_IF -14 */ 59 | "Already connected.", /* ERR_ISCONN -15 */ 60 | }; 61 | 62 | /** 63 | * Convert an lwip internal error to a string representation. 64 | * 65 | * @param err an lwip internal err_t 66 | * @return a string representation for err 67 | */ 68 | const char * 69 | lwip_strerr(err_t err) 70 | { 71 | return err_strerr[-err]; 72 | 73 | } 74 | 75 | #endif /* LWIP_DEBUG */ 76 | -------------------------------------------------------------------------------- /src/lwip-esp/core/Makefile: -------------------------------------------------------------------------------- 1 | subdirs-y+=ipv4 2 | objects-y+=def.o 3 | objects-y+=dhcp.o 4 | objects-y+=dns.o 5 | objects-y+=init.o 6 | objects-y+=mem.o 7 | objects-y+=memp.o 8 | objects-y+=netif.o 9 | objects-y+=pbuf.o 10 | objects-y+=raw.o 11 | objects-y+=stats.o 12 | objects-y+=sys.o 13 | objects-y+=tcp.o 14 | objects-y+=tcp_in.o 15 | objects-y+=tcp_out.o 16 | objects-y+=timers.o 17 | objects-y+=udp.o 18 | -------------------------------------------------------------------------------- /src/lwip-esp/core/ipv4/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=autoip.o 2 | objects-y+=icmp.o 3 | objects-y+=igmp.o 4 | objects-y+=inet.o 5 | objects-y+=inet_chksum.o 6 | objects-y+=ip_addr.o 7 | objects-y+=ip.o 8 | objects-y+=ip_frag.o 9 | -------------------------------------------------------------------------------- /src/lwip-esp/core/ipv4/inet.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Functions common to all TCP/IPv4 modules, such as the byte order functions. 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/inet.h" 42 | 43 | -------------------------------------------------------------------------------- /src/lwip-esp/core/sys.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * lwIP Operating System abstraction 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/sys.h" 42 | 43 | /* Most of the functions defined in sys.h must be implemented in the 44 | * architecture-dependent file sys_arch.c */ 45 | 46 | #if !NO_SYS 47 | 48 | /** 49 | * Sleep for some ms. Timeouts are NOT processed while sleeping. 50 | * 51 | * @param ms number of milliseconds to sleep 52 | */ 53 | void 54 | sys_msleep(u32_t ms) 55 | { 56 | if (ms > 0) { 57 | sys_sem_t delaysem; 58 | err_t err = sys_sem_new(&delaysem, 0); 59 | if (err == ERR_OK) { 60 | sys_arch_sem_wait(&delaysem, ms); 61 | sys_sem_free(&delaysem); 62 | } 63 | } 64 | } 65 | 66 | #endif /* !NO_SYS */ 67 | -------------------------------------------------------------------------------- /src/lwip-esp/include/ipv4/lwip/ip_frag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Jani Monoses 30 | * 31 | */ 32 | 33 | #ifndef __LWIP_IP_FRAG_H__ 34 | #define __LWIP_IP_FRAG_H__ 35 | 36 | #include "lwip/opt.h" 37 | #include "lwip/err.h" 38 | #include "lwip/pbuf.h" 39 | #include "lwip/netif.h" 40 | #include "lwip/ip_addr.h" 41 | #include "lwip/ip.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #if IP_REASSEMBLY 48 | /* The IP reassembly timer interval in milliseconds. */ 49 | #define IP_TMR_INTERVAL 1000 50 | 51 | /* IP reassembly helper struct. 52 | * This is exported because memp needs to know the size. 53 | */ 54 | struct ip_reassdata { 55 | struct ip_reassdata *next; 56 | struct pbuf *p; 57 | struct ip_hdr iphdr; 58 | u16_t datagram_len; 59 | u8_t flags; 60 | u8_t timer; 61 | }; 62 | 63 | void ip_reass_init(void); 64 | void ip_reass_tmr(void); 65 | struct pbuf * ip_reass(struct pbuf *p); 66 | #endif /* IP_REASSEMBLY */ 67 | 68 | #if IP_FRAG 69 | #if !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF 70 | /** A custom pbuf that holds a reference to another pbuf, which is freed 71 | * when this custom pbuf is freed. This is used to create a custom PBUF_REF 72 | * that points into the original pbuf. */ 73 | struct pbuf_custom_ref { 74 | /** 'base class' */ 75 | struct pbuf_custom pc; 76 | /** pointer to the original pbuf that is referenced */ 77 | struct pbuf *original; 78 | }; 79 | #endif /* !IP_FRAG_USES_STATIC_BUF && !LWIP_NETIF_TX_SINGLE_PBUF */ 80 | 81 | err_t ip_frag(struct pbuf *p, struct netif *netif, ip_addr_t *dest); 82 | #endif /* IP_FRAG */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* __LWIP_IP_FRAG_H__ */ 89 | -------------------------------------------------------------------------------- /src/lwip-esp/include/lwip/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef __LWIP_INIT_H__ 33 | #define __LWIP_INIT_H__ 34 | 35 | #include "lwip/opt.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** X.x.x: Major version of the stack */ 42 | #define LWIP_VERSION_MAJOR 1U 43 | /** x.X.x: Minor version of the stack */ 44 | #define LWIP_VERSION_MINOR 4U 45 | /** x.x.X: Revision of the stack */ 46 | #define LWIP_VERSION_REVISION 0U 47 | /** For release candidates, this is set to 1..254 48 | * For official releases, this is set to 255 (LWIP_RC_RELEASE) 49 | * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ 50 | #define LWIP_VERSION_RC 2U 51 | 52 | /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ 53 | #define LWIP_RC_RELEASE 255U 54 | /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ 55 | #define LWIP_RC_DEVELOPMENT 0U 56 | 57 | #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) 58 | #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) 59 | #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) 60 | 61 | /** Provides the version of the stack */ 62 | #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ 63 | LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) 64 | 65 | /* Modules initialization */ 66 | void lwip_init(void); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* __LWIP_INIT_H__ */ 73 | -------------------------------------------------------------------------------- /src/lwip-esp/netif/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=etharp.o 2 | -------------------------------------------------------------------------------- /src/lwip-git/FILES: -------------------------------------------------------------------------------- 1 | api/ - The code for the high-level wrapper API. Not needed if 2 | you use the lowel-level call-back/raw API. 3 | 4 | core/ - The core of the TPC/IP stack; protocol implementations, 5 | memory and buffer management, and the low-level raw API. 6 | 7 | include/ - lwIP include files. 8 | 9 | netif/ - Generic network interface device drivers are kept here, 10 | as well as the ARP module. 11 | 12 | For more information on the various subdirectories, check the FILES 13 | file in each directory. 14 | -------------------------------------------------------------------------------- /src/lwip-git/Makefile: -------------------------------------------------------------------------------- 1 | subdirs-y += api core netif 2 | -------------------------------------------------------------------------------- /src/lwip-git/api/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=api_lib.o 2 | objects-y+=api_msg.o 3 | objects-y+=err.o 4 | objects-y+=netbuf.o 5 | objects-y+=netdb.o 6 | objects-y+=netifapi.o 7 | objects-y+=sockets.o 8 | objects-y+=tcpip.o 9 | -------------------------------------------------------------------------------- /src/lwip-git/api/err.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * Error Management module 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/err.h" 40 | 41 | #ifdef LWIP_DEBUG 42 | 43 | static const char *err_strerr[] = { 44 | "Ok.", /* ERR_OK 0 */ 45 | "Out of memory error.", /* ERR_MEM -1 */ 46 | "Buffer error.", /* ERR_BUF -2 */ 47 | "Timeout.", /* ERR_TIMEOUT -3 */ 48 | "Routing problem.", /* ERR_RTE -4 */ 49 | "Operation in progress.", /* ERR_INPROGRESS -5 */ 50 | "Illegal value.", /* ERR_VAL -6 */ 51 | "Operation would block.", /* ERR_WOULDBLOCK -7 */ 52 | "Address in use.", /* ERR_USE -8 */ 53 | "Already connected.", /* ERR_ISCONN -9 */ 54 | "Not connected.", /* ERR_CONN -10 */ 55 | "Connection aborted.", /* ERR_ABRT -11 */ 56 | "Connection reset.", /* ERR_RST -12 */ 57 | "Connection closed.", /* ERR_CLSD -13 */ 58 | "Illegal argument.", /* ERR_ARG -14 */ 59 | "Low-level netif error.", /* ERR_IF -15 */ 60 | }; 61 | 62 | /** 63 | * Convert an lwip internal error to a string representation. 64 | * 65 | * @param err an lwip internal err_t 66 | * @return a string representation for err 67 | */ 68 | const char * 69 | lwip_strerr(err_t err) 70 | { 71 | return err_strerr[-err]; 72 | 73 | } 74 | 75 | #endif /* LWIP_DEBUG */ 76 | -------------------------------------------------------------------------------- /src/lwip-git/core/Makefile: -------------------------------------------------------------------------------- 1 | subdirs-y+=ipv4 2 | objects-y+=def.o 3 | objects-y+=dhcp.o 4 | objects-y+=dns.o 5 | objects-y+=inet_chksum.o 6 | objects-y+=init.o 7 | objects-y+=mem.o 8 | objects-y+=memp.o 9 | objects-y+=netif.o 10 | objects-y+=pbuf.o 11 | objects-y+=raw.o 12 | objects-y+=stats.o 13 | objects-y+=sys.o 14 | objects-y+=tcp.o 15 | objects-y+=tcp_in.o 16 | objects-y+=tcp_out.o 17 | objects-y+=timers.o 18 | objects-y+=udp.o 19 | -------------------------------------------------------------------------------- /src/lwip-git/core/ipv4/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=autoip.o 2 | objects-y+=icmp.o 3 | objects-y+=igmp.o 4 | objects-y+=ip4_addr.o 5 | objects-y+=ip4.o 6 | objects-y+=ip_frag.o 7 | -------------------------------------------------------------------------------- /src/lwip-git/core/ipv6/README: -------------------------------------------------------------------------------- 1 | IPv6 support in lwIP is very experimental. 2 | -------------------------------------------------------------------------------- /src/lwip-git/core/ipv6/dhcp6.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * DHCPv6. 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2010 Inico Technologies Ltd. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Ivan Delamer 36 | * 37 | * 38 | * Please coordinate changes and requests with Ivan Delamer 39 | * 40 | */ 41 | 42 | #include "lwip/opt.h" 43 | 44 | #if LWIP_IPV6 && LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */ 45 | 46 | #include "lwip/ip6_addr.h" 47 | #include "lwip/def.h" 48 | 49 | 50 | #endif /* LWIP_IPV6 && LWIP_IPV6_DHCP6 */ 51 | -------------------------------------------------------------------------------- /src/lwip-git/core/ipv6/inet6.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * INET v6 addresses. 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2010 Inico Technologies Ltd. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Ivan Delamer 36 | * 37 | * 38 | * Please coordinate changes and requests with Ivan Delamer 39 | * 40 | */ 41 | 42 | #include "lwip/opt.h" 43 | 44 | #if LWIP_IPV6 && LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 45 | 46 | #include "lwip/def.h" 47 | #include "lwip/inet.h" 48 | 49 | /** This variable is initialized by the system to contain the wildcard IPv6 address. 50 | */ 51 | const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; 52 | 53 | #endif /* LWIP_IPV6 */ 54 | -------------------------------------------------------------------------------- /src/lwip-git/core/sys.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * lwIP Operating System abstraction 4 | * 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Adam Dunkels 36 | * 37 | */ 38 | 39 | #include "lwip/opt.h" 40 | 41 | #include "lwip/sys.h" 42 | 43 | /* Most of the functions defined in sys.h must be implemented in the 44 | * architecture-dependent file sys_arch.c */ 45 | 46 | #if !NO_SYS 47 | 48 | #ifndef sys_msleep 49 | /** 50 | * Sleep for some ms. Timeouts are NOT processed while sleeping. 51 | * 52 | * @param ms number of milliseconds to sleep 53 | */ 54 | void 55 | sys_msleep(u32_t ms) 56 | { 57 | if (ms > 0) { 58 | sys_sem_t delaysem; 59 | err_t err = sys_sem_new(&delaysem, 0); 60 | if (err == ERR_OK) { 61 | sys_arch_sem_wait(&delaysem, ms); 62 | sys_sem_free(&delaysem); 63 | } 64 | } 65 | } 66 | #endif /* sys_msleep */ 67 | 68 | #endif /* !NO_SYS */ 69 | -------------------------------------------------------------------------------- /src/lwip-git/include/lwip/dhcp6.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * IPv6 address autoconfiguration as per RFC 4862. 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2010 Inico Technologies Ltd. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Ivan Delamer 36 | * 37 | * IPv6 address autoconfiguration as per RFC 4862. 38 | * 39 | * Please coordinate changes and requests with Ivan Delamer 40 | * 41 | */ 42 | 43 | #ifndef LWIP_HDR_IP6_DHCP6_H 44 | #define LWIP_HDR_IP6_DHCP6_H 45 | 46 | #include "lwip/opt.h" 47 | 48 | #if LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */ 49 | 50 | 51 | struct dhcp6 52 | { 53 | /*TODO: implement DHCP6*/ 54 | }; 55 | 56 | #endif /* LWIP_IPV6_DHCP6 */ 57 | 58 | #endif /* LWIP_HDR_IP6_DHCP6_H */ 59 | -------------------------------------------------------------------------------- /src/lwip-git/include/lwip/ethip6.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * 4 | * Ethernet output for IPv6. Uses ND tables for link-layer addressing. 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2010 Inico Technologies Ltd. 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without modification, 12 | * are permitted provided that the following conditions are met: 13 | * 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, 17 | * this list of conditions and the following disclaimer in the documentation 18 | * and/or other materials provided with the distribution. 19 | * 3. The name of the author may not be used to endorse or promote products 20 | * derived from this software without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31 | * OF SUCH DAMAGE. 32 | * 33 | * This file is part of the lwIP TCP/IP stack. 34 | * 35 | * Author: Ivan Delamer 36 | * 37 | * 38 | * Please coordinate changes and requests with Ivan Delamer 39 | * 40 | */ 41 | 42 | #ifndef LWIP_HDR_ETHIP6_H 43 | #define LWIP_HDR_ETHIP6_H 44 | 45 | #include "lwip/opt.h" 46 | 47 | #if LWIP_IPV6 && LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */ 48 | 49 | #include "lwip/pbuf.h" 50 | #include "lwip/ip6.h" 51 | #include "lwip/ip6_addr.h" 52 | #include "lwip/netif.h" 53 | 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | 60 | err_t ethip6_output(struct netif *netif, struct pbuf *q, const ip6_addr_t *ip6addr); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* LWIP_IPV6 && LWIP_ETHERNET */ 67 | 68 | #endif /* LWIP_HDR_ETHIP6_H */ 69 | -------------------------------------------------------------------------------- /src/lwip-git/include/lwip/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without modification, 6 | * are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 25 | * OF SUCH DAMAGE. 26 | * 27 | * This file is part of the lwIP TCP/IP stack. 28 | * 29 | * Author: Adam Dunkels 30 | * 31 | */ 32 | #ifndef LWIP_HDR_INIT_H 33 | #define LWIP_HDR_INIT_H 34 | 35 | #include "lwip/opt.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /** X.x.x: Major version of the stack */ 42 | #define LWIP_VERSION_MAJOR 1U 43 | /** x.X.x: Minor version of the stack */ 44 | #define LWIP_VERSION_MINOR 4U 45 | /** x.x.X: Revision of the stack */ 46 | #define LWIP_VERSION_REVISION 1U 47 | /** For release candidates, this is set to 1..254 48 | * For official releases, this is set to 255 (LWIP_RC_RELEASE) 49 | * For development versions (CVS), this is set to 0 (LWIP_RC_DEVELOPMENT) */ 50 | #define LWIP_VERSION_RC 0U 51 | 52 | /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ 53 | #define LWIP_RC_RELEASE 255U 54 | /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for CVS versions */ 55 | #define LWIP_RC_DEVELOPMENT 0U 56 | 57 | #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) 58 | #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) 59 | #define LWIP_VERSION_IS_RC ((LWIP_VERSION_RC != LWIP_RC_RELEASE) && (LWIP_VERSION_RC != LWIP_RC_DEVELOPMENT)) 60 | 61 | /** Provides the version of the stack */ 62 | #define LWIP_VERSION (LWIP_VERSION_MAJOR << 24 | LWIP_VERSION_MINOR << 16 | \ 63 | LWIP_VERSION_REVISION << 8 | LWIP_VERSION_RC) 64 | 65 | /* Modules initialization */ 66 | void lwip_init(void); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* LWIP_HDR_INIT_H */ 73 | -------------------------------------------------------------------------------- /src/lwip-git/include/netif/ppp/chap-md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * chap-md5.h - New CHAP/MD5 implementation. 3 | * 4 | * Copyright (c) 2003 Paul Mackerras. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. The name(s) of the authors of this software must not be used to 14 | * endorse or promote products derived from this software without 15 | * prior written permission. 16 | * 17 | * 3. Redistributions of any form whatsoever must retain the following 18 | * acknowledgment: 19 | * "This product includes software developed by Paul Mackerras 20 | * ". 21 | * 22 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 23 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 24 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 27 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 28 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 29 | */ 30 | 31 | #include "lwip/opt.h" 32 | #if PPP_SUPPORT && CHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 33 | 34 | extern const struct chap_digest_type md5_digest; 35 | 36 | #endif /* PPP_SUPPORT && CHAP_SUPPORT */ 37 | -------------------------------------------------------------------------------- /src/lwip-git/include/netif/ppp/chap_ms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * chap_ms.h - Challenge Handshake Authentication Protocol definitions. 3 | * 4 | * Copyright (c) 1995 Eric Rosenquist. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * 3. The name(s) of the authors of this software must not be used to 19 | * endorse or promote products derived from this software without 20 | * prior written permission. 21 | * 22 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 23 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 24 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 25 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 26 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 27 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 28 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 29 | * 30 | * $Id: chap_ms.h,v 1.13 2004/11/15 22:13:26 paulus Exp $ 31 | */ 32 | 33 | #include "lwip/opt.h" 34 | #if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 35 | 36 | #ifndef __CHAPMS_INCLUDE__ 37 | 38 | extern const struct chap_digest_type chapms_digest; 39 | extern const struct chap_digest_type chapms2_digest; 40 | 41 | #define __CHAPMS_INCLUDE__ 42 | #endif /* __CHAPMS_INCLUDE__ */ 43 | 44 | #endif /* PPP_SUPPORT && MSCHAP_SUPPORT */ 45 | -------------------------------------------------------------------------------- /src/lwip-git/include/netif/ppp/ecp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ecp.h - Definitions for PPP Encryption Control Protocol. 3 | * 4 | * Copyright (c) 2002 Google, Inc. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in 16 | * the documentation and/or other materials provided with the 17 | * distribution. 18 | * 19 | * 3. The name(s) of the authors of this software must not be used to 20 | * endorse or promote products derived from this software without 21 | * prior written permission. 22 | * 23 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 24 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 25 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 26 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 27 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 28 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 29 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 30 | * 31 | * $Id: ecp.h,v 1.2 2003/01/10 07:12:36 fcusack Exp $ 32 | */ 33 | 34 | #include "lwip/opt.h" 35 | #if PPP_SUPPORT && ECP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 36 | 37 | typedef struct ecp_options { 38 | bool required; /* Is ECP required? */ 39 | unsigned enctype; /* Encryption type */ 40 | } ecp_options; 41 | 42 | extern fsm ecp_fsm[]; 43 | extern ecp_options ecp_wantoptions[]; 44 | extern ecp_options ecp_gotoptions[]; 45 | extern ecp_options ecp_allowoptions[]; 46 | extern ecp_options ecp_hisoptions[]; 47 | 48 | extern const struct protent ecp_protent; 49 | 50 | #endif /* PPP_SUPPORT && ECP_SUPPORT */ 51 | -------------------------------------------------------------------------------- /src/lwip-git/include/netif/ppp/polarssl/arc4.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file arc4.h 3 | * 4 | * Based on XySSL: Copyright (C) 2006-2008 Christophe Devine 5 | * 6 | * Copyright (C) 2009 Paul Bakker 7 | * 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * * Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * * Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * * Neither the names of PolarSSL or XySSL nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 29 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include "lwip/opt.h" 37 | #if LWIP_INCLUDED_POLARSSL_ARC4 38 | 39 | #ifndef LWIP_INCLUDED_POLARSSL_ARC4_H 40 | #define LWIP_INCLUDED_POLARSSL_ARC4_H 41 | 42 | /** 43 | * \brief ARC4 context structure 44 | */ 45 | typedef struct 46 | { 47 | int x; /*!< permutation index */ 48 | int y; /*!< permutation index */ 49 | unsigned char m[256]; /*!< permutation table */ 50 | } 51 | arc4_context; 52 | 53 | #ifdef __cplusplus 54 | extern "C" { 55 | #endif 56 | 57 | /** 58 | * \brief ARC4 key schedule 59 | * 60 | * \param ctx ARC4 context to be initialized 61 | * \param key the secret key 62 | * \param keylen length of the key 63 | */ 64 | void arc4_setup( arc4_context *ctx, unsigned char *key, int keylen ); 65 | 66 | /** 67 | * \brief ARC4 cipher function 68 | * 69 | * \param ctx ARC4 context 70 | * \param buf buffer to be processed 71 | * \param buflen amount of data in buf 72 | */ 73 | void arc4_crypt( arc4_context *ctx, unsigned char *buf, int buflen ); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* LWIP_INCLUDED_POLARSSL_ARC4_H */ 80 | 81 | #endif /* LWIP_INCLUDED_POLARSSL_ARC4 */ 82 | -------------------------------------------------------------------------------- /src/lwip-git/include/netif/ppp/pppcrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1 3 | * 4 | * Extracted from chap_ms.c by James Carlson. 5 | * 6 | * Copyright (c) 1995 Eric Rosenquist. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. The name(s) of the authors of this software must not be used to 21 | * endorse or promote products derived from this software without 22 | * prior written permission. 23 | * 24 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 25 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 26 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 27 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 29 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 30 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | */ 32 | 33 | #include "lwip/opt.h" 34 | #if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not configured for use in lwipopts.h */ 35 | 36 | #ifndef PPPCRYPT_H 37 | #define PPPCRYPT_H 38 | 39 | void pppcrypt_56_to_64_bit_key(u_char *key, u_char *des_key); 40 | 41 | #endif /* PPPCRYPT_H */ 42 | 43 | #endif /* PPP_SUPPORT && MSCHAP_SUPPORT */ 44 | -------------------------------------------------------------------------------- /src/lwip-git/include/posix/netdb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/netdb.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/netdb.h" 34 | -------------------------------------------------------------------------------- /src/lwip-git/include/posix/sys/socket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 3 | * This file is a posix wrapper for lwip/sockets.h. 4 | */ 5 | 6 | /* 7 | * Redistribution and use in source and binary forms, with or without modification, 8 | * are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 3. The name of the author may not be used to endorse or promote products 16 | * derived from this software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 27 | * OF SUCH DAMAGE. 28 | * 29 | * This file is part of the lwIP TCP/IP stack. 30 | * 31 | */ 32 | 33 | #include "lwip/sockets.h" 34 | -------------------------------------------------------------------------------- /src/lwip-git/netif/FILES: -------------------------------------------------------------------------------- 1 | This directory contains generic network interface device drivers that 2 | do not contain any hardware or architecture specific code. The files 3 | are: 4 | 5 | etharp.c 6 | Implements the ARP (Address Resolution Protocol) over 7 | Ethernet. The code in this file should be used together with 8 | Ethernet device drivers. Note that this module has been 9 | largely made Ethernet independent so you should be able to 10 | adapt this for other link layers (such as Firewire). 11 | 12 | ethernetif.c 13 | An example of how an Ethernet device driver could look. This 14 | file can be used as a "skeleton" for developing new Ethernet 15 | network device drivers. It uses the etharp.c ARP code. 16 | 17 | loopif.c 18 | A "loopback" network interface driver. It requires configuration 19 | through the define LWIP_LOOPIF_MULTITHREADING (see opt.h). 20 | 21 | slipif.c 22 | A generic implementation of the SLIP (Serial Line IP) 23 | protocol. It requires a sio (serial I/O) module to work. 24 | 25 | ppp/ Point-to-Point Protocol stack 26 | The lwIP PPP support is based from pppd (http://ppp.samba.org) with 27 | huge changes to match code size and memory requirements for embedded 28 | devices. Please read ppp/PPPD_FOLLOWUP for a detailed explanation. 29 | -------------------------------------------------------------------------------- /src/lwip-git/netif/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=etharp.o 2 | -------------------------------------------------------------------------------- /src/lwip-git/netif/ppp/eui64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * eui64.c - EUI64 routines for IPv6CP. 3 | * 4 | * Copyright (c) 1999 Tommi Komulainen. All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * 3. The name(s) of the authors of this software must not be used to 19 | * endorse or promote products derived from this software without 20 | * prior written permission. 21 | * 22 | * 4. Redistributions of any form whatsoever must retain the following 23 | * acknowledgment: 24 | * "This product includes software developed by Tommi Komulainen 25 | * ". 26 | * 27 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 28 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 29 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 30 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 31 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 32 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 33 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 34 | * 35 | * $Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp $ 36 | */ 37 | 38 | #include "lwip/opt.h" 39 | #if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */ 40 | 41 | #include "netif/ppp/ppp_impl.h" 42 | #include "netif/ppp/eui64.h" 43 | 44 | /* 45 | * eui64_ntoa - Make an ascii representation of an interface identifier 46 | */ 47 | char *eui64_ntoa(eui64_t e) { 48 | static char buf[20]; 49 | 50 | sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x", 51 | e.e8[0], e.e8[1], e.e8[2], e.e8[3], 52 | e.e8[4], e.e8[5], e.e8[6], e.e8[7]); 53 | return buf; 54 | } 55 | 56 | #endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */ 57 | -------------------------------------------------------------------------------- /src/lwip-git/netif/ppp/polarssl/README: -------------------------------------------------------------------------------- 1 | About PolarSSL files into lwIP PPP support 2 | ------------------------------------------ 3 | 4 | This folder contains some files fetched from the latest BSD release of 5 | the PolarSSL project for ciphers and encryption methods we need for lwIP 6 | PPP support. 7 | 8 | The PolarSSL files were cleaned to contain only the necessary struct 9 | fields and functions needed for lwIP. 10 | 11 | 12 | The PolarSSL API was not changed at all, so if you are already using 13 | PolarSSL you can choose to skip the compilation of the included PolarSSL 14 | library into lwIP: 15 | 16 | The following defines are available for flexibility: 17 | 18 | LWIP_INCLUDED_POLARSSL_MD4 ; Use lwIP internal PolarSSL for MD4 19 | LWIP_INCLUDED_POLARSSL_MD5 ; Use lwIP internal PolarSSL for MD5 20 | LWIP_INCLUDED_POLARSSL_SHA1 ; Use lwIP internal PolarSSL for SHA1 21 | LWIP_INCLUDED_POLARSSL_DES ; Use lwIP internal PolarSSL for DES 22 | LWIP_INCLUDED_POLARSSL_ARC4 ; Use lwIP internal PolarSSL for ARC4 23 | 24 | If set (=1), the default if required by another enabled PPP feature unless 25 | explicitly set to 0, using included lwIP PolarSSL. 26 | 27 | If clear (=0), not needed or using external PolarSSL. 28 | 29 | Beware of the stack requirements which can be a lot larger if you are not 30 | using our cleaned PolarSSL library. 31 | 32 | 33 | PolarSSL project website: http://polarssl.org/ 34 | -------------------------------------------------------------------------------- /src/lwip-git/netif/ppp/pppcrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1 3 | * 4 | * Extracted from chap_ms.c by James Carlson. 5 | * 6 | * Copyright (c) 1995 Eric Rosenquist. All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in 17 | * the documentation and/or other materials provided with the 18 | * distribution. 19 | * 20 | * 3. The name(s) of the authors of this software must not be used to 21 | * endorse or promote products derived from this software without 22 | * prior written permission. 23 | * 24 | * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 25 | * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 26 | * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 27 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 28 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 29 | * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 30 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 31 | */ 32 | 33 | #include "lwip/opt.h" 34 | #if PPP_SUPPORT && MSCHAP_SUPPORT /* don't build if not necessary */ 35 | 36 | #include "netif/ppp/ppp_impl.h" 37 | 38 | #include "netif/ppp/pppcrypt.h" 39 | 40 | 41 | static u_char pppcrypt_get_7bits(u_char *input, int startBit) { 42 | unsigned int word; 43 | 44 | word = (unsigned)input[startBit / 8] << 8; 45 | word |= (unsigned)input[startBit / 8 + 1]; 46 | 47 | word >>= 15 - (startBit % 8 + 7); 48 | 49 | return word & 0xFE; 50 | } 51 | 52 | /* IN 56 bit DES key missing parity bits 53 | * OUT 64 bit DES key with parity bits added 54 | */ 55 | void pppcrypt_56_to_64_bit_key(u_char *key, u_char * des_key) { 56 | des_key[0] = pppcrypt_get_7bits(key, 0); 57 | des_key[1] = pppcrypt_get_7bits(key, 7); 58 | des_key[2] = pppcrypt_get_7bits(key, 14); 59 | des_key[3] = pppcrypt_get_7bits(key, 21); 60 | des_key[4] = pppcrypt_get_7bits(key, 28); 61 | des_key[5] = pppcrypt_get_7bits(key, 35); 62 | des_key[6] = pppcrypt_get_7bits(key, 42); 63 | des_key[7] = pppcrypt_get_7bits(key, 49); 64 | } 65 | 66 | #endif /* PPP_SUPPORT && MSCHAP_SUPPORT */ 67 | -------------------------------------------------------------------------------- /src/mqtt/Makefile: -------------------------------------------------------------------------------- 1 | objects-y+=config.o 2 | objects-y+=mqtt.o 3 | objects-y+=mqtt_msg.o 4 | objects-y+=proto.o 5 | objects-y+=queue.o 6 | objects-y+=ringbuf.o 7 | objects-y+=utils.o 8 | -------------------------------------------------------------------------------- /src/mqtt/queue.c: -------------------------------------------------------------------------------- 1 | /* str_queue.c 2 | * 3 | * Copyright (c) 2014-2015, Tuan PM 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * * Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * * Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * * Neither the name of Redis nor the names of its contributors may be used 15 | * to endorse or promote products derived from this software without 16 | * specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | #include 31 | 32 | #include "user_interface.h" 33 | #include "osapi.h" 34 | #include "os_type.h" 35 | #include "mem.h" 36 | #include 37 | void ICACHE_FLASH_ATTR QUEUE_Init(QUEUE *queue, int bufferSize) 38 | { 39 | queue->buf = (uint8_t*)os_zalloc(bufferSize); 40 | RINGBUF_Init(&queue->rb, queue->buf, bufferSize); 41 | } 42 | int32_t ICACHE_FLASH_ATTR QUEUE_Puts(QUEUE *queue, uint8_t* buffer, uint16_t len) 43 | { 44 | return PROTO_AddRb(&queue->rb, buffer, len); 45 | } 46 | int32_t ICACHE_FLASH_ATTR QUEUE_Gets(QUEUE *queue, uint8_t* buffer, uint16_t* len, uint16_t maxLen) 47 | { 48 | 49 | return PROTO_ParseRb(&queue->rb, buffer, len, maxLen); 50 | } 51 | 52 | BOOL ICACHE_FLASH_ATTR QUEUE_IsEmpty(QUEUE *queue) 53 | { 54 | if(queue->rb.fill_cnt<=0) 55 | return TRUE; 56 | return FALSE; 57 | } 58 | -------------------------------------------------------------------------------- /src/mqtt/ringbuf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * Ring Buffer library 4 | */ 5 | 6 | #include 7 | 8 | 9 | /** 10 | * \brief init a RINGBUF object 11 | * \param r pointer to a RINGBUF object 12 | * \param buf pointer to a byte array 13 | * \param size size of buf 14 | * \return 0 if successfull, otherwise failed 15 | */ 16 | I16 ICACHE_FLASH_ATTR RINGBUF_Init(RINGBUF *r, U8* buf, I32 size) 17 | { 18 | if(r == NULL || buf == NULL || size < 2) return -1; 19 | 20 | r->p_o = r->p_r = r->p_w = buf; 21 | r->fill_cnt = 0; 22 | r->size = size; 23 | 24 | return 0; 25 | } 26 | /** 27 | * \brief put a character into ring buffer 28 | * \param r pointer to a ringbuf object 29 | * \param c character to be put 30 | * \return 0 if successfull, otherwise failed 31 | */ 32 | I16 ICACHE_FLASH_ATTR RINGBUF_Put(RINGBUF *r, U8 c) 33 | { 34 | if(r->fill_cnt>=r->size)return -1; // ring buffer is full, this should be atomic operation 35 | 36 | 37 | r->fill_cnt++; // increase filled slots count, this should be atomic operation 38 | 39 | 40 | *r->p_w++ = c; // put character into buffer 41 | 42 | if(r->p_w >= r->p_o + r->size) // rollback if write pointer go pass 43 | r->p_w = r->p_o; // the physical boundary 44 | 45 | return 0; 46 | } 47 | /** 48 | * \brief get a character from ring buffer 49 | * \param r pointer to a ringbuf object 50 | * \param c read character 51 | * \return 0 if successfull, otherwise failed 52 | */ 53 | I16 ICACHE_FLASH_ATTR RINGBUF_Get(RINGBUF *r, U8* c) 54 | { 55 | if(r->fill_cnt<=0)return -1; // ring buffer is empty, this should be atomic operation 56 | 57 | 58 | r->fill_cnt--; // decrease filled slots count 59 | 60 | 61 | *c = *r->p_r++; // get the character out 62 | 63 | if(r->p_r >= r->p_o + r->size) // rollback if write pointer go pass 64 | r->p_r = r->p_o; // the physical boundary 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /src/netapps-is-not-compiled/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekromant/esp8266-frankenstein/3188970703aceb67587f6081baa2ae5cc8bf9350/src/netapps-is-not-compiled/Makefile -------------------------------------------------------------------------------- /src/netapps-is-not-compiled/dhcpserver.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nekromant/esp8266-frankenstein/3188970703aceb67587f6081baa2ae5cc8bf9350/src/netapps-is-not-compiled/dhcpserver.c -------------------------------------------------------------------------------- /src/pin_map.c: -------------------------------------------------------------------------------- 1 | #include "pin_map.h" 2 | #include "eagle_soc.h" 3 | 4 | uint32_t pin_mux[GPIO_PIN_NUM] = { 5 | PERIPHS_IO_MUX_GPIO0_U, PERIPHS_IO_MUX_U0TXD_U, PERIPHS_IO_MUX_GPIO2_U, PERIPHS_IO_MUX_U0RXD_U, 6 | PERIPHS_IO_MUX_GPIO4_U, PERIPHS_IO_MUX_GPIO5_U, -1, -1, 7 | -1, PERIPHS_IO_MUX_SD_DATA2_U, PERIPHS_IO_MUX_SD_DATA3_U, -1, 8 | PERIPHS_IO_MUX_MTDI_U, PERIPHS_IO_MUX_MTCK_U, PERIPHS_IO_MUX_MTMS_U, PERIPHS_IO_MUX_MTDO_U, 9 | PAD_XPD_DCDC_CONF 10 | }; 11 | 12 | uint8_t pin_func[GPIO_PIN_NUM] = { 13 | FUNC_GPIO0, FUNC_GPIO1, FUNC_GPIO2, FUNC_GPIO3, 14 | FUNC_GPIO4, FUNC_GPIO5, -1, -1, 15 | -1, FUNC_GPIO9, FUNC_GPIO10, -1, 16 | FUNC_GPIO12, FUNC_GPIO13, FUNC_GPIO14, FUNC_GPIO15, 17 | -1 18 | }; 19 | 20 | 21 | bool is_valid_gpio_pin(uint8 gpiopin) 22 | { 23 | if(gpiopin >= GPIO_PIN_NUM) return false; 24 | return (pin_func[gpiopin] != GPIO_PIN_FUNC_INVALID); 25 | } 26 | -------------------------------------------------------------------------------- /src/sched.c: -------------------------------------------------------------------------------- 1 | #include "user_interface.h" 2 | #include "missing.h" 3 | 4 | #include "espconn.h" 5 | #include "gpio.h" 6 | #include "main.h" 7 | #include "helpers.h" 8 | #include "sched.h" 9 | #include "env.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #define MAX_SCHED_ENTRIES 10 17 | 18 | static uint8_t last; 19 | static uint16_t mod; 20 | ETSTimer schedTimer; 21 | 22 | static void sched_timer_cb(void *); 23 | 24 | struct { 25 | int modulus; 26 | const char *cmd; 27 | } schedule[MAX_SCHED_ENTRIES]; 28 | 29 | void ICACHE_FLASH_ATTR 30 | sched_init(void) 31 | { 32 | last = 0; 33 | mod = 0; 34 | os_timer_disarm(&schedTimer); 35 | os_timer_setfn(&schedTimer, (os_timer_func_t *)sched_timer_cb, NULL); 36 | } 37 | 38 | int ICACHE_FLASH_ATTR 39 | sched_add(const char *cmd, int mod) 40 | { 41 | if (last < MAX_SCHED_ENTRIES) { 42 | if (cmd != NULL && mod) { 43 | schedule[last].cmd = cmd; 44 | schedule[last].modulus = mod; 45 | } 46 | last++; 47 | } 48 | else 49 | return -1; 50 | if (last == 1) // First entry, arm the timer 51 | { 52 | os_timer_arm(&schedTimer, 1000, 1); 53 | console_printf("Timer armed, 1000ms\r\n"); 54 | } 55 | 56 | return last; 57 | } 58 | 59 | static void ICACHE_FLASH_ATTR 60 | sched_timer_cb(void *arg) 61 | { 62 | int i; 63 | 64 | if (last == 0) { // Sanity check. 65 | os_timer_disarm(&schedTimer); 66 | return; 67 | } 68 | 69 | for (i=0;i \r\n"); 102 | return 0; 103 | } 104 | mod = (uint16_t)skip_atoul((const char **)&argv[1]); 105 | 106 | if (mod == 0) 107 | return -1; 108 | if (argv[2][0] == '$') // run an environment variable instead 109 | { 110 | cmd = (char *)env_get(&(argv[2][1])); 111 | if (cmd == NULL) 112 | return -1; 113 | } 114 | else { 115 | l = strlen(argv[2]); // Assume cmd is a single arg in ''s 116 | 117 | cmd = os_malloc(l); 118 | if (cmd == NULL) { 119 | console_printf("Out of memory?\r\n"); 120 | return -1; 121 | } 122 | strcpy(cmd, argv[2]); 123 | } 124 | 125 | console_printf("Scheduling [%s] to execute every %d seconds\r\n", cmd, mod); 126 | 127 | return sched_add(cmd, mod); 128 | } 129 | 130 | CONSOLE_CMD(every, -1, 3, 131 | do_every, NULL, NULL, 132 | "Execute console cmd every N seconds" 133 | HELPSTR_NEWLINE "every 10 'gpio out 5 1 ; gpio out 5 0'" 134 | HELPSTR_NEWLINE "every 10 $envvar" 135 | ); 136 | -------------------------------------------------------------------------------- /src/sensorloggers/adc.c: -------------------------------------------------------------------------------- 1 | #include "user_interface.h" 2 | #include "missing.h" 3 | 4 | #include "espconn.h" 5 | #include "gpio.h" 6 | #include "driver/uart.h" 7 | #include "microrl.h" 8 | #include "console.h" 9 | #include "main.h" 10 | #include "helpers.h" 11 | #include "lwip/sys.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | static double get_adc(struct slogger_data_type *tp) 20 | { 21 | return (double) system_adc_read() / 1024.0 * 1000.0; 22 | } 23 | 24 | FR_CONSTRUCTOR(register_adc_logger) 25 | { 26 | console_printf("senslogger: Registering adc sensor\n"); 27 | struct slogger_data_type *dt = malloc(sizeof(*dt)); 28 | 29 | dt->type = "Voltage"; 30 | dt->description = "ADC Voltage"; 31 | dt->unit = "mV"; 32 | dt->get_current_value = get_adc; 33 | sensorlogger_instance_register_data_type(svclog_get_global_instance(), dt); 34 | } 35 | -------------------------------------------------------------------------------- /src/sensorloggers/vdd3v3.c: -------------------------------------------------------------------------------- 1 | #include "user_interface.h" 2 | #include "missing.h" 3 | 4 | #include "espconn.h" 5 | #include "gpio.h" 6 | #include "driver/uart.h" 7 | #include "microrl.h" 8 | #include "console.h" 9 | #include "main.h" 10 | #include "helpers.h" 11 | #include "lwip/sys.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | static double get_vdd3v3(struct slogger_data_type *tp) 20 | { 21 | return (double) readvdd33(); 22 | } 23 | 24 | FR_CONSTRUCTOR(register_vdd3v3_logger) 25 | { 26 | console_printf("senslogger: Registering vdd3v3 sensor\n"); 27 | struct slogger_data_type *dt = malloc(sizeof(*dt)); 28 | 29 | dt->type = "Voltage"; 30 | dt->description = "VDD3V3 Voltage"; 31 | dt->unit = "mV"; 32 | dt->get_current_value = get_vdd3v3; 33 | sensorlogger_instance_register_data_type(svclog_get_global_instance(), dt); 34 | } 35 | -------------------------------------------------------------------------------- /src/stdio.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | #if 0 5 | 6 | _ssize_t _write_r (struct _reent *r, int file, const void *ptr, size_t len) 7 | { 8 | 9 | } 10 | 11 | _ssize_t _read_r(struct _reent *r, int file, void *ptr, size_t len) 12 | { 13 | 14 | } 15 | 16 | #endif -------------------------------------------------------------------------------- /src/svc_aura.c: -------------------------------------------------------------------------------- 1 | #include "tcpservice.h" 2 | #include "env.h" 3 | #include "main.h" 4 | 5 | #define AURA_BUFFER_SIZE 32 6 | static int connected = 0; 7 | static size_t aura_recv (tcpservice_t* peer, const char* data, size_t len) 8 | { 9 | /* Write data to aura */ 10 | return tcp_service_write(peer, data, len); 11 | } 12 | 13 | static void aura_ack (tcpservice_t* peer, size_t len) 14 | { 15 | connected++; 16 | tcp_service_allow_more(peer, len); 17 | } 18 | 19 | static tcpservice_t* aura_new_peer (tcpservice_t* listener) 20 | { 21 | tcpservice_t* peer = tcp_service_init_new_peer_size(AURA_BUFFER_SIZE); 22 | if (peer) 23 | { 24 | peer->cb_recv = aura_recv; 25 | peer->cb_ack = aura_ack; 26 | } 27 | return peer; 28 | } 29 | 30 | static tcpservice_t aura_listener = TCP_SERVICE_LISTENER("aura", aura_new_peer); 31 | 32 | int aura_start (int port) 33 | { 34 | if (port <= 0) 35 | port = 10102; 36 | console_printf("Starting aura rpc server @ port %d\n", port); 37 | return tcp_service_install("aura", &aura_listener, port); 38 | } 39 | 40 | static int do_aura(int argc, const char* const* argv) 41 | { 42 | if (strcmp(argv[1], "start") == 0) 43 | return aura_start(-1); 44 | else 45 | console_printf("aura: invalid command '%s'\n", argv[1]); 46 | 47 | return 0; 48 | } 49 | 50 | CONSOLE_CMD(aura, 2, 2, 51 | do_aura, NULL, NULL, 52 | "start/stop aura rpc server" 53 | HELPSTR_NEWLINE "aura start - start aura service"); 54 | -------------------------------------------------------------------------------- /src/svc_echo.c: -------------------------------------------------------------------------------- 1 | 2 | #include "tcpservice.h" 3 | #include "env.h" 4 | #include "main.h" 5 | 6 | // for that service, lower value than TCP_WND leads to loss of data 7 | // see discussion in tcpservice.h, and have a try :) 8 | //#define ECHO_SEND_BUFFER_SIZE ((TCP_WND) - 1) // too short 9 | //#define ECHO_SEND_BUFFER_SIZE ((TCP_WND) / 2) // too short 10 | #define ECHO_SEND_BUFFER_SIZE (TCP_WND) 11 | 12 | /////////////////////////////////////////////////////////// 13 | // callbacks for tcp service 14 | 15 | static tcpservice_t* echo_new_peer (tcpservice_t* s); 16 | static size_t echo_recv (tcpservice_t* s, const char* data, size_t len); 17 | static void echo_ack (tcpservice_t* s, size_t len); 18 | 19 | /////////////////////////////////////////////////////////// 20 | // static data (small ram footprint) 21 | 22 | // tcp server only, takes no space 23 | // (the "socketserver" awaiting for incoming request only) 24 | static tcpservice_t echo_listener = TCP_SERVICE_LISTENER("echo", echo_new_peer); 25 | 26 | /////////////////////////////////////////////////////////// 27 | 28 | static tcpservice_t* echo_new_peer (tcpservice_t* listener) 29 | { 30 | tcpservice_t* peer = tcp_service_init_new_peer_size(ECHO_SEND_BUFFER_SIZE); 31 | if (peer) 32 | { 33 | peer->cb_recv = echo_recv; 34 | peer->cb_ack = echo_ack; 35 | } 36 | return peer; 37 | } 38 | 39 | static size_t echo_recv (tcpservice_t* peer, const char* data, size_t len) 40 | { 41 | return tcp_service_write(peer, data, len); 42 | } 43 | 44 | static void echo_ack (tcpservice_t* peer, size_t len) 45 | { 46 | tcp_service_allow_more(peer, len); 47 | } 48 | 49 | int echo_start (int port) 50 | { 51 | if (port <= 0) 52 | port = 10102; 53 | return tcp_service_install("echo", &echo_listener, port); 54 | } 55 | 56 | static int do_echo(int argc, const char* const* argv) 57 | { 58 | if (strcmp(argv[1], "start") == 0) 59 | return echo_start(-1); 60 | else 61 | console_printf("echo: invalid command '%s'\n", argv[1]); 62 | 63 | return 0; 64 | } 65 | 66 | CONSOLE_CMD(echo, 2, 2, 67 | do_echo, NULL, NULL, 68 | "start/stop tcp echo server" 69 | HELPSTR_NEWLINE "echo start - start service"); 70 | -------------------------------------------------------------------------------- /src/user_config.h: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/user_rf_cal_sector_set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void ICACHE_FLASH_ATTR 5 | user_rf_pre_init(void) 6 | { 7 | ets_uart_printf("RF PREINIT\n"); 8 | } 9 | 10 | 11 | uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void) { 12 | extern char flashchip; 13 | SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4); 14 | // We know that sector size in 4096 15 | //uint32_t sec_num = flash->chip_size / flash->sector_size; 16 | uint32_t sec_num = flash->chip_size >> 12; 17 | ets_uart_printf("Flash %d bytes calibration data @ %x\n", 18 | flash->chip_size, sec_num-5); 19 | return sec_num - 5; 20 | } 21 | --------------------------------------------------------------------------------