diff --git a/.cproject b/.cproject index e279948..6948854 100644 --- a/.cproject +++ b/.cproject @@ -25,6 +25,11 @@ + + + + + @@ -36,6 +41,11 @@ + + + + + @@ -47,6 +57,11 @@ + + + + + @@ -72,4 +87,5 @@ + diff --git a/.project b/.project index ce4ae9c..8b21cc7 100644 --- a/.project +++ b/.project @@ -31,6 +31,16 @@ io.sloeber.arduinonature + + I2Cdev + 2 + C:/Users/agr/Nextcloud3/Fileserver/inet4all/Projekte/SmartFarm/Libraries/I2Cdev + + + IAQ2000 + 2 + C:/Users/agr/Nextcloud3/Fileserver/inet4all/Projekte/SmartFarm/Libraries/IAQ2000 + core/core 2 @@ -39,7 +49,17 @@ core/variant 2 - ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/variants/mega + ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/variants/eightanaloginputs + + + libraries/Adafruit_Unified_Sensor + 2 + ECLIPSE_HOME/arduinoPlugin/libraries/Adafruit_Unified_Sensor/1.1.2 + + + libraries/DHT_sensor_library + 2 + ECLIPSE_HOME/arduinoPlugin/libraries/DHT_sensor_library/1.3.8 libraries/EEPROM @@ -61,5 +81,10 @@ 2 ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/libraries/SPI + + libraries/Wire + 2 + ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/libraries/Wire + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 9969d91..9f6c658 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -4,7 +4,7 @@ - + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 5269f99..6ab7273 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -13,10 +13,10 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.EXT environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.EXTENDED_FUSES/value=0xFD environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.FILE/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.FILE/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.FILE/value=stk500v2/stk500boot_v2_mega2560.hex +environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.FILE/value=atmega/ATmegaBOOT_168_atmega328.hex environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.HIGH_FUSES/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.HIGH_FUSES/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.HIGH_FUSES/value=0xD8 +environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.HIGH_FUSES/value=0xDA environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.LOCK_BITS/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.LOCK_BITS/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.BOOTLOADER.LOCK_BITS/value=0x0F @@ -34,7 +34,7 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.ARCH/ope environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.ARCH/value=AVR environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.BOARD/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.BOARD/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.BOARD/value=AVR_MEGA2560 +environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.BOARD/value=AVR_NANO environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.CORE.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.CORE.PATH/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.CORE.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\cores\\arduino @@ -49,7 +49,7 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.F_CPU/op environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.F_CPU/value=16000000L environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.MCU/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.MCU/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.MCU/value=atmega2560 +environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.MCU/value=atmega328p environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.PATH/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.PATH/value=${ProjDirPath}/${ConfigName} @@ -67,10 +67,10 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.USB_MANU environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.USB_MANUFACTURER/value=\\"Unknown\\" environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT.PATH/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT.PATH/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\variants\\mega +environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT.PATH/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\variants\\eightanaloginputs environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT/value=mega +environment/project/io.sloeber.core.toolChain.release.613547860/A.BUILD.VARIANT/value=eightanaloginputs environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.AR.CMD/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.AR.CMD/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.AR.CMD/value=avr-gcc-ar @@ -91,7 +91,7 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF.EXTRA_FLAGS/value= environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF.FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF.FLAGS/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF.FLAGS/value=${A.COMPILER.WARNING_FLAGS} -Os -Wl,--gc-sections,--relax +environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.ELF.FLAGS/value=${A.COMPILER.WARNING_FLAGS} -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.EXTRA_FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.EXTRA_FLAGS/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.COMPILER.C.EXTRA_FLAGS/value= @@ -160,28 +160,10 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.ESP8266.NETWOR environment/project/io.sloeber.core.toolChain.release.613547860/A.ESP8266.NETWORK.UPLOAD.TOOL/value=esp8266OTA environment/project/io.sloeber.core.toolChain.release.613547860/A.NAME/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.NAME/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.NAME/value=Arduino Mega or Mega 2560 +environment/project/io.sloeber.core.toolChain.release.613547860/A.NAME/value=Arduino Nano environment/project/io.sloeber.core.toolChain.release.613547860/A.PACKAGES/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.PACKAGES/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.PACKAGES/value=${eclipse_home}/arduinoPlugin/packages -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.0/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.0/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.0/value=0x0010 -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.1/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.1/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.1/value=0x0042 -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.2/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.2/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.2/value=0x0010 -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.3/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.3/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.3/value=0x0042 -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.4/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.4/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.4/value=0x0210 -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.5/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.5/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.PID.5/value=0x0242 environment/project/io.sloeber.core.toolChain.release.613547860/A.PREPROC.INCLUDES.FLAGS/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.PREPROC.INCLUDES.FLAGS/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.PREPROC.INCLUDES.FLAGS/value=-w -x c++ -M -MG -MP @@ -424,16 +406,16 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.ALTID/o environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.ALTID/value=no_altID environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_DATA_SIZE/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_DATA_SIZE/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_DATA_SIZE/value=8192 +environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_DATA_SIZE/value=2048 environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_SIZE/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_SIZE/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_SIZE/value=253952 +environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.MAXIMUM_SIZE/value=30720 environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.PROTOCOL/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.PROTOCOL/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.PROTOCOL/value=wiring +environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.PROTOCOL/value=arduino environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.SPEED/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.SPEED/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.SPEED/value=115200 +environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.SPEED/value=57600 environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.TOOL/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.TOOL/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.TOOL/value=avrdude @@ -443,24 +425,6 @@ environment/project/io.sloeber.core.toolChain.release.613547860/A.UPLOAD.USBID/v environment/project/io.sloeber.core.toolChain.release.613547860/A.VERSION/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/A.VERSION/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/A.VERSION/value=1.8.2 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.0/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.0/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.0/value=0x2341 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.1/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.1/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.1/value=0x2341 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.2/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.2/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.2/value=0x2A03 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.3/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.3/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.3/value=0x2A03 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.4/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.4/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.4/value=0x2341 -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.5/delimiter=; -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.5/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/A.VID.5/value=0x2341 environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ARCHITECTURE_ID/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ARCHITECTURE_ID/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ARCHITECTURE_ID/value=avr @@ -469,13 +433,13 @@ environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARDS_FI environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARDS_FILE/value=C\:\\Sloeber\\arduinoPlugin\\packages\\arduino\\hardware\\avr\\1.8.2\\boards.txt environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_ID/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_ID/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_ID/value=mega +environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_ID/value=nano environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_NAME/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_NAME/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_NAME/value=Arduino Mega or Mega 2560 +environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.BOARD_NAME/value=Arduino Nano environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.COM_PORT/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.COM_PORT/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.COM_PORT/value=COM4 +environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.COM_PORT/value=COM7 environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ECLIPSE_LOCATION/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ECLIPSE_LOCATION/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.ECLIPSE_LOCATION/value=C\:\\Sloeber\\ @@ -505,7 +469,7 @@ environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MAKE_LOCA environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MAKE_LOCATION/value=C\:\\Sloeber\\arduinoPlugin\\tools\\make\\ environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MENU/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MENU/operation=replace -environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MENU/value=cpu\=atmega2560 +environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.MENU/value=cpu\=atmega328old environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.OBJCOPY/delimiter=; environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.OBJCOPY/operation=replace environment/project/io.sloeber.core.toolChain.release.613547860/JANTJE.OBJCOPY/value=${A.RECIPE.OBJCOPY.EEP.PATTERN}\n\t${A.RECIPE.OBJCOPY.HEX.PATTERN} diff --git a/Web_Net_Setup.ino b/Web_Net_Setup.ino index 83c3210..f4da9d2 100644 --- a/Web_Net_Setup.ino +++ b/Web_Net_Setup.ino @@ -1,337 +1,346 @@ /* Web_Net_Setup.pde - example for a webinterface to set the network configuration -Author: Matthias Maderer -Date: 07.03.2013 -Version: 1.0.1 -web: www.edvler-blog.de/arduino_networksetup_webinterface_with_eeprom + Author: Matthias Maderer + Date: 07.03.2013 + Version: 1.0.1 + web: www.edvler-blog.de/arduino_networksetup_webinterface_with_eeprom -This is a sample Sketch for Webduino! -More informations about Webduino can be found at https://github.com/sirleech/Webduino + This is a sample Sketch for Webduino! + More informations about Webduino can be found at https://github.com/sirleech/Webduino -For more informations about EEPROMAnything.h look at http://playground.arduino.cc/Code/EEPROMWriteAnything -*/ + For more informations about EEPROMAnything.h look at http://playground.arduino.cc/Code/EEPROMWriteAnything + */ /* -* With this example its possible to configure the network configuration of the -* Arduino Ethernet Shield with a webinterface. Imagine like your router setup. -* -* It's possible to configure the following network settings: -* - MAC address -* - IP address -* - Subnet -* - Gateway -* - DNS Server -* - Webserver port -* - USE DHCP YES/NO (if you use DHCP connect per serial port - 9600 baud - on powerup to see which ip address is assigned) -* - DHCP renew interval -* -* Other functions: -* - Display DHCP renew status -* - Display DHCP renew timestamp -* - Display Arduino uptime -* - Display used RAM -* -* You can configure default settings. This settings are used wenn no configuration is present. -* Look at the function set_EEPROM_Default(). -* -* It is possible to connect a RESET button. If the button is pressed and the Arduino is turned on -* the default values would be restored too. -* See #define RESET_PIN. -* -* -* All settings are stored in EEPROM. This means they are permanent. -* Please look at http://arduino.cc/en/Reference/EEPROM for a short description. -* -* -* To setup your arduino upload this sketch. -* -* If you don't change the sourcecode the default IP address is http://192.168.0.111/ -* Don't forget to change the IP of your network adapter to a suitable address (e.g. to IP 192.168.0.1, NETMASK 255.255.255.0)! -* -* Enter the following URL for the setup page: -* http://192.168.0.111/setupNet.html -* -* Please note that no input checks are done!! -* This means that no error would be thrown if you type a wrong IP address or other failures. -* Keep this in mind. -* -* Resources: -* There are many Strings for the HTML site. The compiled size is about 27.000 Bytes. Aprox. 2000 byte of SRAM is used. -* On smaller Arduinos this may cause problems. I've tested it on a MEGA 2560. -* -* BUGS: -* - After uploading your sketch the arduino is not reachable. --> Reset your Arduino!! -*/ - + * With this example its possible to configure the network configuration of the + * Arduino Ethernet Shield with a webinterface. Imagine like your router setup. + * + * It's possible to configure the following network settings: + * - MAC address + * - IP address + * - Subnet + * - Gateway + * - DNS Server + * - Webserver port + * - USE DHCP YES/NO (if you use DHCP connect per serial port - 9600 baud - on powerup to see which ip address is assigned) + * - DHCP renew interval + * + * Other functions: + * - Display DHCP renew status + * - Display DHCP renew timestamp + * - Display Arduino uptime + * - Display used RAM + * + * You can configure default settings. This settings are used wenn no configuration is present. + * Look at the function set_EEPROM_Default(). + * + * It is possible to connect a RESET button. If the button is pressed and the Arduino is turned on + * the default values would be restored too. + * See #define RESET_PIN. + * + * + * All settings are stored in EEPROM. This means they are permanent. + * Please look at http://arduino.cc/en/Reference/EEPROM for a short description. + * + * + * To setup your arduino upload this sketch. + * + * If you don't change the sourcecode the default IP address is http://192.168.0.111/ + * Don't forget to change the IP of your network adapter to a suitable address (e.g. to IP 192.168.0.1, NETMASK 255.255.255.0)! + * + * Enter the following URL for the setup page: + * http://192.168.0.111/setupNet.html + * + * Please note that no input checks are done!! + * This means that no error would be thrown if you type a wrong IP address or other failures. + * Keep this in mind. + * + * Resources: + * There are many Strings for the HTML site. The compiled size is about 27.000 Bytes. Aprox. 2000 byte of SRAM is used. + * On smaller Arduinos this may cause problems. I've tested it on a MEGA 2560. + * + * BUGS: + * - After uploading your sketch the arduino is not reachable. --> Reset your Arduino!! + */ //#define WEBDUINO_FAVICON_DATA "" // no favicon -#define DEBUG //uncomment for serial debug output -#define USE_SYSTEM_LIBRARY //comment out if you want to save some space (about 1 Byte). You wouldn't see uptime and free RAM if it's commented out. +//#define DEBUG //uncomment for serial debug output +//#define USE_SYSTEM_LIBRARY //comment out if you want to save some space (about 1 Byte). You wouldn't see uptime and free RAM if it's commented out. #define SERIAL_BAUD 9600 - #include "SPI.h" // new include #include "avr/pgmspace.h" // new include #include "Ethernet.h" #include "WebServer.h" #include - +#include "IAQ2000.h" +#include "I2Cdev.h" +#include /* ############################################################################################################################################################# -* Code for the EEPROM related things -* -*/ + * Code for the EEPROM related things + * + */ //#include //#include "EEPROMAnything.h" - -#define RESET_PIN 40 //Connect a button to this PIN. If the button is hold, an the device is turned on the default ethernet settings are restored. +#define RESET_PIN 8 //Connect a button to this PIN. If the button is hold, an the device is turned on the default ethernet settings are restored. /* structure which is stored in the eeprom. -* Look at "EEPROMAnything.h" for the functions storing and reading the struct -*/ + * Look at "EEPROMAnything.h" for the functions storing and reading the struct + */ #include "struct.h" -//MQTT intern include -//#include "mqttintern.h" +#define dht_apin 5 + +IAQ2000 iaq; + +DHT dht(dht_apin, DHT11); + +uint16_t airQuality; +int val = 0; +float Temperatur; +float Humidity; +unsigned long loopcnt = 0; /** -* set_EEPROM_Default() function -* -* The default settings. -* This settings are used when no config is present or the reset button is pressed. -*/ + * set_EEPROM_Default() function + * + * The default settings. + * This settings are used when no config is present or the reset button is pressed. + */ void set_EEPROM_Default() { - eeprom_config.config_set=1; // dont change! It's used to check if the config is already set - - eeprom_config.use_dhcp=0; // use DHCP per default - eeprom_config.dhcp_refresh_minutes=60; // refresh the DHCP every 60 minutes - - // set the default MAC address. In this case its DE:AD:BE:EF:FE:ED - eeprom_config.mac[0]=0xDE; - eeprom_config.mac[1]=0xAD; - eeprom_config.mac[2]=0xBE; - eeprom_config.mac[3]=0xEF; - eeprom_config.mac[4]=0xFE; - eeprom_config.mac[5]=0xED; - - // set the default IP address for the arduino. In this case its 192.168.1.97 - eeprom_config.ip[0]=192; - eeprom_config.ip[1]=168; - eeprom_config.ip[2]=1; - eeprom_config.ip[3]=97; - - // set the default GATEWAY. In this case its 192.168.1.1 - eeprom_config.gateway[0]=192; - eeprom_config.gateway[1]=168; - eeprom_config.gateway[2]=1; - eeprom_config.gateway[3]=1; - - // set the default SUBNET. In this case its 255.255.255.0 - eeprom_config.subnet[0]=255; - eeprom_config.subnet[1]=255; - eeprom_config.subnet[2]=255; - eeprom_config.subnet[3]=0; - - // set the default DNS SERVER. In this case its 192.168.1.1 - eeprom_config.dns_server[0]=192; - eeprom_config.dns_server[1]=168; - eeprom_config.dns_server[2]=1; - eeprom_config.dns_server[3]=1; - - // set the default Webserver Port. In this case its Port 80 - eeprom_config.webserverPort=80; - - // set the default MQTT SERVER. In this case its 192.168.1.35 - eeprom_config.mqtt_server[0]=192; - eeprom_config.mqtt_server[1]=168; - eeprom_config.mqtt_server[2]=1; - eeprom_config.mqtt_server[3]=35; - - // set the default Webserver Port. In this case its Port 80 - eeprom_config.mqttserverPort=1883; - #ifdef DEBUG - Serial.println("Config reset"); - #endif + eeprom_config.config_set = 1; // dont change! It's used to check if the config is already set + + eeprom_config.use_dhcp = 0; // use DHCP per default + eeprom_config.dhcp_refresh_minutes = 60; // refresh the DHCP every 60 minutes + + // set the default MAC address. In this case its DE:AD:BE:EF:FE:ED + eeprom_config.mac[0] = 0xDE; + eeprom_config.mac[1] = 0xAD; + eeprom_config.mac[2] = 0xBE; + eeprom_config.mac[3] = 0xEF; + eeprom_config.mac[4] = 0xFE; + eeprom_config.mac[5] = 0xED; + + // set the default IP address for the arduino. In this case its 192.168.1.97 + eeprom_config.ip[0] = 192; + eeprom_config.ip[1] = 168; + eeprom_config.ip[2] = 1; + eeprom_config.ip[3] = 97; + + // set the default GATEWAY. In this case its 192.168.1.1 + eeprom_config.gateway[0] = 192; + eeprom_config.gateway[1] = 168; + eeprom_config.gateway[2] = 1; + eeprom_config.gateway[3] = 1; + + // set the default SUBNET. In this case its 255.255.255.0 + eeprom_config.subnet[0] = 255; + eeprom_config.subnet[1] = 255; + eeprom_config.subnet[2] = 255; + eeprom_config.subnet[3] = 0; + + // set the default DNS SERVER. In this case its 192.168.1.1 + eeprom_config.dns_server[0] = 192; + eeprom_config.dns_server[1] = 168; + eeprom_config.dns_server[2] = 1; + eeprom_config.dns_server[3] = 1; + + // set the default Webserver Port. In this case its Port 80 + eeprom_config.webserverPort = 80; + + // set the default MQTT SERVER. In this case its 192.168.1.35 + eeprom_config.mqtt_server[0] = 192; + eeprom_config.mqtt_server[1] = 168; + eeprom_config.mqtt_server[2] = 1; + eeprom_config.mqtt_server[3] = 35; + + // set the default Webserver Port. In this case its Port 80 + eeprom_config.mqttserverPort = 1883; +#ifdef DEBUG + Serial.println("Config reset"); +#endif } - /** -* read_EEPROM_Settings function -* This function is used to read the EEPROM settings at startup -* -* Overview: -* - Set the PIN for the RESET-button to input and activate pullups -* - Load the stored data from EEPROM into the eeprom_config struct -* - Check if a config is stored or the reset button is pressed. If one of the conditions is ture, set the defaults -*/ + * read_EEPROM_Settings function + * This function is used to read the EEPROM settings at startup + * + * Overview: + * - Set the PIN for the RESET-button to input and activate pullups + * - Load the stored data from EEPROM into the eeprom_config struct + * - Check if a config is stored or the reset button is pressed. If one of the conditions is ture, set the defaults + */ void read_EEPROM_Settings() { - pinMode(RESET_PIN, INPUT); - digitalWrite(RESET_PIN, HIGH); - - // read the current config - EEPROM_readAnything(0, eeprom_config); - - // check if config is present or if reset button is pressed - if (eeprom_config.config_set != 1 || digitalRead(RESET_PIN) == LOW) { - // set default values - set_EEPROM_Default(); - - // write the config to eeprom - EEPROM_writeAnything(0, eeprom_config); - } + pinMode(RESET_PIN, INPUT); + digitalWrite(RESET_PIN, HIGH); + + // read the current config + EEPROM_readAnything(0, eeprom_config); + + // check if config is present or if reset button is pressed + if (eeprom_config.config_set != 1 || digitalRead(RESET_PIN) == LOW) { + // set default values + set_EEPROM_Default(); + + // write the config to eeprom + EEPROM_writeAnything(0, eeprom_config); + } } /** -* print_EEPROM_Settings() function -* -* This function is used for debugging the configuration. -* It prints the actual configuration to the serial port. -*/ + * print_EEPROM_Settings() function + * + * This function is used for debugging the configuration. + * It prints the actual configuration to the serial port. + */ #ifdef DEBUG void print_EEPROM_Settings() { - Serial.print("IP: "); - for(int i = 0; i<4; i++) { - Serial.print(eeprom_config.ip[i]); - if (i<3) { - Serial.print('.'); - } - } - Serial.println(); - - Serial.print("Subnet: "); - for(int i = 0; i<4; i++) { - Serial.print(eeprom_config.subnet[i]); - if (i<3) { - Serial.print('.'); - } - } - Serial.println(); - - Serial.print("Gateway: "); - for(int i = 0; i<4; i++) { - Serial.print(eeprom_config.gateway[i]); - if (i<3) { - Serial.print('.'); - } - } - Serial.println(); - - Serial.print("DNS Server: "); - for(int i = 0; i<4; i++) { - Serial.print(eeprom_config.dns_server[i]); - if (i<3) { - Serial.print('.'); - } - } - Serial.println(); - - Serial.print("MQTT Server: "); - for(int i = 0; i<4; i++) { - Serial.print(eeprom_config.mqtt_server[i]); - if (i<3) { - Serial.print('.'); - } - } - Serial.println(); - - Serial.print("MAC: "); - for (int a=0;a<6;a++) { - Serial.print(eeprom_config.mac[a],HEX); - if(a<5) { - Serial.print(":"); - } - } - Serial.println(); - Serial.print("MQTTserver Port: "); - Serial.println(eeprom_config.mqttserverPort); - - Serial.print("Webserver Port: "); - Serial.println(eeprom_config.webserverPort); - - Serial.print("USE DHCP: "); - Serial.println(eeprom_config.use_dhcp); - - Serial.print(" DHCP renew every "); - Serial.print(eeprom_config.dhcp_refresh_minutes); - Serial.println(" minutes"); - - Serial.print("Config Set: "); - Serial.println(eeprom_config.config_set); + Serial.print("IP: "); + for (int i = 0; i < 4; i++) { + Serial.print(eeprom_config.ip[i]); + if (i < 3) { + Serial.print('.'); + } + } + Serial.println(); + + Serial.print("Subnet: "); + for (int i = 0; i < 4; i++) { + Serial.print(eeprom_config.subnet[i]); + if (i < 3) { + Serial.print('.'); + } + } + Serial.println(); + + Serial.print("Gateway: "); + for (int i = 0; i < 4; i++) { + Serial.print(eeprom_config.gateway[i]); + if (i < 3) { + Serial.print('.'); + } + } + Serial.println(); + + Serial.print("DNS Server: "); + for (int i = 0; i < 4; i++) { + Serial.print(eeprom_config.dns_server[i]); + if (i < 3) { + Serial.print('.'); + } + } + Serial.println(); + + Serial.print("MQTT Server: "); + for (int i = 0; i < 4; i++) { + Serial.print(eeprom_config.mqtt_server[i]); + if (i < 3) { + Serial.print('.'); + } + } + Serial.println(); + + Serial.print("MAC: "); + for (int a = 0; a < 6; a++) { + Serial.print(eeprom_config.mac[a], HEX); + if (a < 5) { + Serial.print(":"); + } + } + Serial.println(); + Serial.print("MQTTserver Port: "); + Serial.println(eeprom_config.mqttserverPort); + + Serial.print("Webserver Port: "); + Serial.println(eeprom_config.webserverPort); + + Serial.print("USE DHCP: "); + Serial.println(eeprom_config.use_dhcp); + + Serial.print(" DHCP renew every "); + Serial.print(eeprom_config.dhcp_refresh_minutes); + Serial.println(" minutes"); + + Serial.print("Config Set: "); + Serial.println(eeprom_config.config_set); } #endif // ############################################################################################################################################################# - /* START Network section ####################################################################################################################################### -* Code for setting up network connection -*/ + * Code for setting up network connection + */ unsigned long last_dhcp_renew; byte dhcp_state; /** -* renewDHCP() function -* Renew the DHCP relase in a given interval. -* -* Overview: -* - Check if interval = 0 and set it to 1 -* - Check if renew interval is reached and renew the lease -*/ + * renewDHCP() function + * Renew the DHCP relase in a given interval. + * + * Overview: + * - Check if interval = 0 and set it to 1 + * - Check if renew interval is reached and renew the lease + */ void renewDHCP(int interval) { - unsigned long interval_millis = interval * 60000; - - if (interval == 0 ) { - interval = 1; - } - if (eeprom_config.use_dhcp==1) { - if((millis() - last_dhcp_renew) > interval_millis) { - last_dhcp_renew=millis(); - dhcp_state = Ethernet.maintain(); - } - } + unsigned long interval_millis = interval * 60000; + + if (interval == 0) { + interval = 1; + } + if (eeprom_config.use_dhcp == 1) { + if ((millis() - last_dhcp_renew) > interval_millis) { + last_dhcp_renew = millis(); + dhcp_state = Ethernet.maintain(); + } + } } - /** -* setupNetwork() function -* This function is used to setupup the network according to the values stored in the eeprom -* -* Overview: -* - First of all read the EEPROM settings -* - Display a link to the ethernet setup -* - Check if DHCP should be used, if not create instaces of IPAddress for ip, gateway, subnet and dns_server -* - Invoke Ethernet.begin with all parameters if no dhcp is active (Ethernet.begin(mac, ip, dns_server, gateway, subnet);). -* - If DHCP is used invoke only with mac (Ethernet.begin(mac);) and display the ip on the serial console. -*/ + * setupNetwork() function + * This function is used to setupup the network according to the values stored in the eeprom + * + * Overview: + * - First of all read the EEPROM settings + * - Display a link to the ethernet setup + * - Check if DHCP should be used, if not create instaces of IPAddress for ip, gateway, subnet and dns_server + * - Invoke Ethernet.begin with all parameters if no dhcp is active (Ethernet.begin(mac, ip, dns_server, gateway, subnet);). + * - If DHCP is used invoke only with mac (Ethernet.begin(mac);) and display the ip on the serial console. + */ void setupNetwork() { - read_EEPROM_Settings(); - - #ifdef DEBUG - print_EEPROM_Settings(); - #endif - - // byte mac[] = { eeprom_config.mac[0], eeprom_config.mac[1], eeprom_config.mac[2], eeprom_config.mac[3], eeprom_config.mac[4], eeprom_config.mac[5] }; - - if (eeprom_config.use_dhcp != 1) { - IPAddress ip(eeprom_config.ip[0], eeprom_config.ip[1], eeprom_config.ip[2], eeprom_config.ip[3]); - IPAddress gateway (eeprom_config.gateway[0],eeprom_config.gateway[1],eeprom_config.gateway[2],eeprom_config.gateway[3]); - IPAddress subnet (eeprom_config.subnet[0], eeprom_config.subnet[1], eeprom_config.subnet[2], eeprom_config.subnet[3]); - IPAddress dns_server (eeprom_config.dns_server[0], eeprom_config.dns_server[1], eeprom_config.dns_server[2], eeprom_config.dns_server[3]); - Ethernet.begin(eeprom_config.mac, ip, dns_server, gateway, subnet); - } else { - if (Ethernet.begin(eeprom_config.mac) == 0) { - Serial.print("Failed to configure Ethernet using DHCP"); - } - Serial.println(Ethernet.localIP()); - } + read_EEPROM_Settings(); + +#ifdef DEBUG + print_EEPROM_Settings(); +#endif + + // byte mac[] = { eeprom_config.mac[0], eeprom_config.mac[1], eeprom_config.mac[2], eeprom_config.mac[3], eeprom_config.mac[4], eeprom_config.mac[5] }; + + if (eeprom_config.use_dhcp != 1) { + IPAddress ip(eeprom_config.ip[0], eeprom_config.ip[1], + eeprom_config.ip[2], eeprom_config.ip[3]); + IPAddress gateway(eeprom_config.gateway[0], eeprom_config.gateway[1], + eeprom_config.gateway[2], eeprom_config.gateway[3]); + IPAddress subnet(eeprom_config.subnet[0], eeprom_config.subnet[1], + eeprom_config.subnet[2], eeprom_config.subnet[3]); + IPAddress dns_server(eeprom_config.dns_server[0], + eeprom_config.dns_server[1], eeprom_config.dns_server[2], + eeprom_config.dns_server[3]); + Ethernet.begin(eeprom_config.mac, ip, dns_server, gateway, subnet); + } else { + if (Ethernet.begin(eeprom_config.mac) == 0) { + Serial.print("Failed to configure Ethernet using DHCP"); + } + Serial.println(Ethernet.localIP()); + } } // END Network section ######################################################################################################################################### - /* WEB-Server section ####################################################################################################################################### -* Webserver Code -*/ + * Webserver Code + */ #ifdef USE_SYSTEM_LIBRARY #include "system.h" @@ -339,29 +348,29 @@ System sys; #endif /* Store all string in the FLASH storage to free SRAM. -The P() is a function from Webduino. -*/ -P(Page_start) = "Web_EEPROM_Setup\n"; + The P() is a function from Webduino. + */ +P(Page_start) = "Web_i4a_Arduino_Page\n"; P(Page_end) = ""; P(Http400) = "HTTP 400 - BAD REQUEST"; -P(Index) = "

index.html


This is your main site!
The code is found in the indexHTML() function.
You can add more sites if you need. Please see the well documented source code.

Use the following link to setup the network.
NETWORK SETUP"; +P(Index) = "

index.html


This is your main site!
NETWORK SETUP
Sensor Daten"; P(Form_eth_start) = "
"; P(Form_end) = ""; P(Form_input_send) = ""; P(Form_input_text_start) = "\n"; -P(MAC) = "MAC address: "; -P(IP) = "IP address: "; +P(MAC) = "MAC : "; +P(IP) = "IP : "; P(SUBNET) = "Subnet: "; -P(GW) = "GW address: "; -P(DNS_SERVER) = "DNS server: "; +P(GW) = "GW : "; +P(DNS_SERVER) = "DNS : "; P(WEB_PORT) = "Webserver port (1-65535): "; P(DHCP_ACTIVE) = "Use DHCP: "; P(DHCP_REFRESH) = "Renew interval for DHCP in minutes (1 - 255): "; @@ -382,12 +391,11 @@ P(table_td_start) = ""; P(table_td_end) = ""; P(table_end) = ""; -P(Config_set) = "New configuration stored!
Please turn off and on your Arduino or use the reset button!

"; +P(Config_set) = "New configuration stored!
Please use the reset button!

"; P(DHCP_STATE_TIME) = "DHCP last renew timestamp (sec)"; P(DHCP_STATE) = "DHCP renew return code (sec)"; - P(UPTIME) = "Uptime: "; #ifdef USE_SYSTEM_LIBRARY @@ -396,456 +404,529 @@ P(RAM_2) = " free of "; #endif /* This creates an pointer to instance of the webserver. */ -WebServer * webserver; - +WebServer *webserver; /** -* indexHTML() function -* This function is used to send the index.html to the client. -*/ -void indexHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - /* this line sends the standard "we're all OK" headers back to the - browser */ - server.httpSuccess(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - - server.printP(Index); - - server.printP(Page_end); - + * indexHTML() function + * This function is used to send the index.html to the client. + */ +void indexHTML(WebServer &server, WebServer::ConnectionType type, + char *url_tail, bool tail_complete) { + /* this line sends the standard "we're all OK" headers back to the + browser */ + server.httpSuccess(); + + /* if we're handling a GET or POST, we can output our data here. + For a HEAD request, we just stop after outputting headers. */ + if (type == WebServer::HEAD) + return; + + server.printP(Page_start); + + server.printP(Index); + + server.printP(Page_end); + } /** -* setupNetHTML() function -* This function is used to send the setupNet.html to the client. -* -* Overview: -* - Send a HTTP 200 OK Header -* - If get parameters exists assign them to the corresponding variable in the eeprom_config struct -* - Print the configuration -* -* Parameters are simple numbers. The name of the parameter is converted to an int with the atoi function. -* This saves some code for setting the MAC and IP addresses. -*/ + * setupNetHTML() function + * This function is used to send the setupNet.html to the client. + * + * Overview: + * - Send a HTTP 200 OK Header + * - If get parameters exists assign them to the corresponding variable in the eeprom_config struct + * - Print the configuration + * + * Parameters are simple numbers. The name of the parameter is converted to an int with the atoi function. + * This saves some code for setting the MAC and IP addresses. + */ #define NAMELEN 5 #define VALUELEN 7 -void setupNetHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - URLPARAM_RESULT rc; - char name[NAMELEN]; - char value[VALUELEN]; - boolean params_present = false; - byte param_number = 0; - - /* this line sends the standard "we're all OK" headers back to the - browser */ - server.httpSuccess(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Page_start); - - // check for parameters - if (strlen(url_tail)) { - while (strlen(url_tail)) { - rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN); - if (rc != URLPARAM_EOS) { - params_present=true; - // debug output for parameters - #ifdef DEBUG - Serial.print(name); - server.print(name); - Serial.print(" - "); - server.print(" - "); - Serial.println(value); - server.print(value); - server.print("
"); - #endif - - - param_number = atoi(name); - - // read MAC address - if (param_number >=0 && param_number <=5) { - eeprom_config.mac[param_number]=strtol(value,NULL,16); - } - - // read IP address - if (param_number >=6 && param_number <=9) { - eeprom_config.ip[param_number-6]=atoi(value); - } - - // read SUBNET - if (param_number >=10 && param_number <=13) { - eeprom_config.subnet[param_number-10]=atoi(value); - } - - // read GATEWAY - if (param_number >=14 && param_number <=17) { - eeprom_config.gateway[param_number-14]=atoi(value); - } - - // read DNS-SERVER - if (param_number >=18 && param_number <=21) { - eeprom_config.dns_server[param_number-18]=atoi(value); - } - - // read WEBServer port - if (param_number == 22) { - eeprom_config.webserverPort=atoi(value); - } - - // read DHCP ON/OFF - if (param_number == 23) { - eeprom_config.use_dhcp=atoi(value); - } - - // read DHCP renew interval - if (param_number == 24) { - eeprom_config.dhcp_refresh_minutes=atoi(value); - } - // read MQTT-SERVER - if (param_number >=25 && param_number <=28) { - eeprom_config.mqtt_server[param_number-25]=atoi(value); - } - - // read MQTTServer port - if (param_number == 29) { - eeprom_config.mqttserverPort=atoi(value); - } - - } - } - EEPROM_writeAnything(0, eeprom_config); - } - - //print the form - server.printP(Form_eth_start); - - if(params_present==true) { - server.printP(Config_set); - } - - server.printP(table_start); - - // print the current MAC - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(MAC); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<6;a++) { - server.printP(Form_input_text_start); - server.print(a); - server.printP(Form_input_value); - server.print(eeprom_config.mac[a],HEX); - server.printP(Form_input_size2); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - // print the current IP - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(IP); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<4;a++) { - server.printP(Form_input_text_start); - server.print(a+6); - server.printP(Form_input_value); - server.print(eeprom_config.ip[a]); - server.printP(Form_input_size3); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - - // print the current SUBNET - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(SUBNET); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<4;a++) { - server.printP(Form_input_text_start); - server.print(a+10); - server.printP(Form_input_value); - server.print(eeprom_config.subnet[a]); - server.printP(Form_input_size3); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - // print the current GATEWAY - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(GW); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<4;a++) { - server.printP(Form_input_text_start); - server.print(a+14); - server.printP(Form_input_value); - server.print(eeprom_config.gateway[a]); - server.printP(Form_input_size3); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - // print the current DNS-SERVER - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(DNS_SERVER); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<4;a++) { - server.printP(Form_input_text_start); - server.print(a+18); - server.printP(Form_input_value); - server.print(eeprom_config.dns_server[a]); - server.printP(Form_input_size3); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - - // print the current webserver port - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(WEB_PORT); - server.printP(table_td_end); - server.printP(table_td_start); - server.printP(Form_input_text_start); - server.print(22); - server.printP(Form_input_value); - server.print(eeprom_config.webserverPort); - server.printP(Form_input_end); - server.printP(table_td_end); - server.printP(table_tr_end); - - //print the current DHCP config - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(DHCP_ACTIVE); - server.printP(table_td_end); - server.printP(table_td_start); - server.printP(Form_cb); - server.print("0\""); - if(eeprom_config.use_dhcp != 1) { - server.printP(Form_cb_checked); - } - server.printP(Form_cb_off); - - server.printP(Form_cb); - server.print("1\""); - if(eeprom_config.use_dhcp == 1) { - server.printP(Form_cb_checked); - } - server.printP(Form_cb_on); - server.printP(table_td_end); - server.printP(table_tr_end); - - - - //print the current DHCP renew time - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(DHCP_REFRESH); - server.printP(table_td_end); - server.printP(table_td_start); - server.printP(Form_input_text_start); - server.print(24); - server.printP(Form_input_value); - server.print(eeprom_config.dhcp_refresh_minutes); - server.printP(Form_input_size3); - server.printP(Form_input_end); - server.printP(table_td_end); - server.printP(table_tr_end); - - - // print the current MQTT-SERVER - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(MQTT_SERVER); - server.printP(table_td_end); - server.printP(table_td_start); - for (int a=0;a<4;a++) { - server.printP(Form_input_text_start); - server.print(a+25); - server.printP(Form_input_value); - server.print(eeprom_config.mqtt_server[a]); - server.printP(Form_input_size3); - server.printP(Form_input_end); - } - server.printP(table_td_end); - server.printP(table_tr_end); - - - // print the current mqttserver port - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(MQTT_PORT); - server.printP(table_td_end); - server.printP(table_td_start); - server.printP(Form_input_text_start); - server.print(29); - server.printP(Form_input_value); - server.print(eeprom_config.mqttserverPort); - server.printP(Form_input_end); - server.printP(table_td_end); - server.printP(table_tr_end); - - //print DHCP status - if(eeprom_config.use_dhcp == 1) { - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(DHCP_STATE); - server.printP(table_td_end); - server.printP(table_td_start); - server.print(dhcp_state); - server.printP(table_td_end); - server.printP(table_tr_end); - - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(DHCP_STATE_TIME); - server.printP(table_td_end); - server.printP(table_td_start); - server.print(last_dhcp_renew/1000); - server.printP(table_td_end); - server.printP(table_tr_end); - } - - #ifdef USE_SYSTEM_LIBRARY - //print uptime - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(UPTIME); - server.printP(table_td_end); - server.printP(table_td_start); - server.print(sys.uptime()); - server.printP(table_td_end); - server.printP(table_tr_end); - - server.printP(table_tr_start); - server.printP(table_td_start); - server.printP(RAM_1); - server.print(sys.ramFree()); - server.printP(RAM_2); - server.print(sys.ramSize()); - server.printP(table_td_end); - server.printP(table_tr_end); - #endif - - server.printP(table_end); - - //print the send button - server.printP(Form_input_send); - server.printP(Form_end); - - - - server.printP(Page_end); +void setupNetHTML(WebServer &server, WebServer::ConnectionType type, + char *url_tail, bool tail_complete) { + URLPARAM_RESULT rc; + char name[NAMELEN]; + char value[VALUELEN]; + boolean params_present = false; + byte param_number = 0; + + /* this line sends the standard "we're all OK" headers back to the + browser */ + server.httpSuccess(); + + /* if we're handling a GET or POST, we can output our data here. + For a HEAD request, we just stop after outputting headers. */ + if (type == WebServer::HEAD) + return; + + server.printP(Page_start); + + // check for parameters + if (strlen(url_tail)) { + while (strlen(url_tail)) { + rc = server.nextURLparam(&url_tail, name, NAMELEN, value, VALUELEN); + if (rc != URLPARAM_EOS) { + params_present = true; + // debug output for parameters +#ifdef DEBUG + Serial.print(name); + server.print(name); + Serial.print(" - "); + server.print(" - "); + Serial.println(value); + server.print(value); + server.print("
"); +#endif + + param_number = atoi(name); + + // read MAC address + if (param_number >= 0 && param_number <= 5) { + eeprom_config.mac[param_number] = strtol(value, NULL, 16); + } + + // read IP address + if (param_number >= 6 && param_number <= 9) { + eeprom_config.ip[param_number - 6] = atoi(value); + } + + // read SUBNET + if (param_number >= 10 && param_number <= 13) { + eeprom_config.subnet[param_number - 10] = atoi(value); + } + + // read GATEWAY + if (param_number >= 14 && param_number <= 17) { + eeprom_config.gateway[param_number - 14] = atoi(value); + } + + // read DNS-SERVER + if (param_number >= 18 && param_number <= 21) { + eeprom_config.dns_server[param_number - 18] = atoi(value); + } + + // read WEBServer port + if (param_number == 22) { + eeprom_config.webserverPort = atoi(value); + } + + // read DHCP ON/OFF + if (param_number == 23) { + eeprom_config.use_dhcp = atoi(value); + } + + // read DHCP renew interval + if (param_number == 24) { + eeprom_config.dhcp_refresh_minutes = atoi(value); + } + // read MQTT-SERVER + if (param_number >= 25 && param_number <= 28) { + eeprom_config.mqtt_server[param_number - 25] = atoi(value); + } + + // read MQTTServer port + if (param_number == 29) { + eeprom_config.mqttserverPort = atoi(value); + } + + } + } + EEPROM_writeAnything(0, eeprom_config); + } + + //print the form + server.printP(Form_eth_start); + + if (params_present == true) { + server.printP(Config_set); + } + + server.printP(table_start); + + // print the current MAC + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(MAC); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 6; a++) { + server.printP(Form_input_text_start); + server.print(a); + server.printP(Form_input_value); + server.print(eeprom_config.mac[a], HEX); + server.printP(Form_input_size2); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current IP + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(IP); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 4; a++) { + server.printP(Form_input_text_start); + server.print(a + 6); + server.printP(Form_input_value); + server.print(eeprom_config.ip[a]); + server.printP(Form_input_size3); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current SUBNET + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(SUBNET); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 4; a++) { + server.printP(Form_input_text_start); + server.print(a + 10); + server.printP(Form_input_value); + server.print(eeprom_config.subnet[a]); + server.printP(Form_input_size3); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current GATEWAY + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(GW); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 4; a++) { + server.printP(Form_input_text_start); + server.print(a + 14); + server.printP(Form_input_value); + server.print(eeprom_config.gateway[a]); + server.printP(Form_input_size3); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current DNS-SERVER + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(DNS_SERVER); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 4; a++) { + server.printP(Form_input_text_start); + server.print(a + 18); + server.printP(Form_input_value); + server.print(eeprom_config.dns_server[a]); + server.printP(Form_input_size3); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current webserver port + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(WEB_PORT); + server.printP(table_td_end); + server.printP(table_td_start); + server.printP(Form_input_text_start); + server.print(22); + server.printP(Form_input_value); + server.print(eeprom_config.webserverPort); + server.printP(Form_input_end); + server.printP(table_td_end); + server.printP(table_tr_end); + + //print the current DHCP config + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(DHCP_ACTIVE); + server.printP(table_td_end); + server.printP(table_td_start); + server.printP(Form_cb); + server.print("0\""); + if (eeprom_config.use_dhcp != 1) { + server.printP(Form_cb_checked); + } + server.printP(Form_cb_off); + + server.printP(Form_cb); + server.print("1\""); + if (eeprom_config.use_dhcp == 1) { + server.printP(Form_cb_checked); + } + server.printP(Form_cb_on); + server.printP(table_td_end); + server.printP(table_tr_end); + + //print the current DHCP renew time + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(DHCP_REFRESH); + server.printP(table_td_end); + server.printP(table_td_start); + server.printP(Form_input_text_start); + server.print(24); + server.printP(Form_input_value); + server.print(eeprom_config.dhcp_refresh_minutes); + server.printP(Form_input_size3); + server.printP(Form_input_end); + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current MQTT-SERVER + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(MQTT_SERVER); + server.printP(table_td_end); + server.printP(table_td_start); + for (int a = 0; a < 4; a++) { + server.printP(Form_input_text_start); + server.print(a + 25); + server.printP(Form_input_value); + server.print(eeprom_config.mqtt_server[a]); + server.printP(Form_input_size3); + server.printP(Form_input_end); + } + server.printP(table_td_end); + server.printP(table_tr_end); + + // print the current mqttserver port + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(MQTT_PORT); + server.printP(table_td_end); + server.printP(table_td_start); + server.printP(Form_input_text_start); + server.print(29); + server.printP(Form_input_value); + server.print(eeprom_config.mqttserverPort); + server.printP(Form_input_end); + server.printP(table_td_end); + server.printP(table_tr_end); + + //print DHCP status + if (eeprom_config.use_dhcp == 1) { + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(DHCP_STATE); + server.printP(table_td_end); + server.printP(table_td_start); + server.print(dhcp_state); + server.printP(table_td_end); + server.printP(table_tr_end); + + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(DHCP_STATE_TIME); + server.printP(table_td_end); + server.printP(table_td_start); + server.print(last_dhcp_renew / 1000); + server.printP(table_td_end); + server.printP(table_tr_end); + } + +#ifdef USE_SYSTEM_LIBRARY + //print uptime + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(UPTIME); + server.printP(table_td_end); + server.printP(table_td_start); + server.print(sys.uptime()); + server.printP(table_td_end); + server.printP(table_tr_end); + + server.printP(table_tr_start); + server.printP(table_td_start); + server.printP(RAM_1); + server.print(sys.ramFree()); + server.printP(RAM_2); + server.print(sys.ramSize()); + server.printP(table_td_end); + server.printP(table_tr_end); +#endif + + server.printP(table_end); + //print the send button + server.printP(Form_input_send); + server.printP(Form_end); + + server.printP(Page_end); + +} + +/** + * errorHTML() function + * This function is called whenever a non extisting page is called. + * It sends a HTTP 400 Bad Request header and the same as text. + */ +void errorHTML(WebServer &server, WebServer::ConnectionType type, + char *url_tail, bool tail_complete) { + /* this line sends the standard "HTTP 400 Bad Request" headers back to the + browser */ + server.httpFail(); + + /* if we're handling a GET or POST, we can output our data here. + For a HEAD request, we just stop after outputting headers. */ + if (type == WebServer::HEAD) + return; + + server.printP(Http400); + + server.printP(Page_end); } /** -* errorHTML() function -* This function is called whenever a non extisting page is called. -* It sends a HTTP 400 Bad Request header and the same as text. -*/ -void errorHTML(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) -{ - /* this line sends the standard "HTTP 400 Bad Request" headers back to the - browser */ - server.httpFail(); - - /* if we're handling a GET or POST, we can output our data here. - For a HEAD request, we just stop after outputting headers. */ - if (type == WebServer::HEAD) - return; - - server.printP(Http400); - - server.printP(Page_end); + * sensorHTML() function + * This function is used to send the sensor value HTML to the client. + */ +void sensorHTML(WebServer &server, WebServer::ConnectionType type, + char *url_tail, bool tail_complete) { + + String aq = String(airQuality); + String temp = String(Temperatur, 2); + String hum = String(Humidity, 2); + + /* this line sends the standard "we're all OK" headers back to the + browser */ + server.httpSuccess(); + + /* if we're handling a GET or POST, we can output our data here. + For a HEAD request, we just stop after outputting headers. */ + if (type == WebServer::HEAD) + return; + + server.printP(Page_start); + + server.print("Humidity = "); + server.print(hum); + server.print(" [%]"); + server.print("Temperature = "); + server.print(temp); + server.print(" [C] "); + server.print("CO2 = "); + server.print(aq); + server.print(" [PPM] "); + + server.printP(Page_end); + } // END WEBCODE ###################################################################################################################################################### /** -* setup() function -* This function is called whenever the arduino is turned on. -*/ -void setup() -{ - Serial.begin(SERIAL_BAUD); - - /* initialize the Ethernet adapter with the settings from eeprom */ - delay(200); // some time to settle - setupNetwork(); - delay(200); // some time to settle - - #define PREFIX "" - webserver = new WebServer(PREFIX, eeprom_config.webserverPort); + * setup() function + * This function is called whenever the arduino is turned on. + */ +void setup() { + Serial.begin(SERIAL_BAUD); - /* setup our default command that will be run when the user accesses - * the root page on the server */ - webserver->setDefaultCommand(&indexHTML); + /* initialize the Ethernet adapter with the settings from eeprom */ + delay(200); // some time to settle + setupNetwork(); + delay(200); // some time to settle - /* setup our default command that will be run when the user accesses - * a page NOT on the server */ - webserver->setFailureCommand(&errorHTML); +#define PREFIX "" + webserver = new WebServer(PREFIX, eeprom_config.webserverPort); - /* run the same command if you try to load /index.html, a common - * default page name */ - webserver->addCommand("index.html", &indexHTML); + /* setup our default command that will be run when the user accesses + * the root page on the server */ + webserver->setDefaultCommand(&indexHTML); - /* display a network setup form. The configuration is stored in eeprom */ - webserver->addCommand("setupNet.html", &setupNetHTML); + /* setup our default command that will be run when the user accesses + * a page NOT on the server */ + webserver->setFailureCommand(&errorHTML); - /* start the webserver */ - webserver->begin(); + /* run the same command if you try to load /index.html, a common + * default page name */ + webserver->addCommand("index.html", &indexHTML); + /* display a network setup form. The configuration is stored in eeprom */ + webserver->addCommand("setupNet.html", &setupNetHTML); - MQTTclient.setServer(eeprom_config.mqtt_server, eeprom_config.mqttserverPort); - //MQTTclient.setCallback(MQTTcallback); + /* display sensor values */ + webserver->addCommand("sensor.html", &sensorHTML); + /* start the webserver */ + webserver->begin(); + + MQTTclient.setServer(eeprom_config.mqtt_server, + eeprom_config.mqttserverPort); + //MQTTclient.setCallback(MQTTcallback); + + dht.read(); + airQuality = iaq.getIaqpred(); + Temperatur = dht.readTemperature(); + Humidity = dht.readHumidity(); } /** -* loop() function -* Runs forver .... -* -* Overview: -* - Renew the DHCP lease -* - Serve web clients -* -*/ -void loop() -{ - // renew DHCP lease - renewDHCP(eeprom_config.dhcp_refresh_minutes); - - char buff[200]; - int len = 200; - - /* process incoming connections one at a time forever */ - webserver->processConnection(buff, &len); + * loop() function + * Runs forver .... + * + * Overview: + * - Renew the DHCP lease + * - Serve web clients + * + */ +void loop() { + char buff[200]; + int len = 200; + String aq = String(airQuality); + String temp = String(Temperatur, 2); + String hum = String(Humidity, 2); + + // renew DHCP lease + renewDHCP(eeprom_config.dhcp_refresh_minutes); + + dht.read(); //read data from pin 5 (DHT11) + airQuality = iaq.getIaqpred(); + Temperatur = dht.readTemperature(); + Humidity = dht.readHumidity(); + + if (!MQTTclient.connected()) { + MQTTclient.connect("Arduino", "loxberry", "OSVL0AMqISFXgr5g"); +#ifdef DEBUG + Serial.print("MQTT Client state:"); +#endif + Serial.println(MQTTclient.state()); + // Abonieren von Nachrichten mit dem angegebenen Topic + //MQTTclient.subscribe("/Stall/arduino1/#"); +#ifdef DEBUG + Serial.println("connected to MQTT"); +#endif + } + + if (loopcnt++ % 1000 == 0) { + temp.toCharArray(buff, temp.length()); + MQTTclient.publish("Arduino/Stall/Temperatur", buff); + aq.toCharArray(buff, aq.length() + 1); + MQTTclient.publish("Arduino/Stall/CO2", buff); +#ifdef DEBUG + Serial.println("CO2 buff"); +#endif + hum.toCharArray(buff, hum.length()); + MQTTclient.publish("Arduino/Stall/Humidity", buff); + snprintf(buff, 19, "%ld", millis()); +#ifdef DEBUG + Serial.println("Publish message: "); + Serial.println(buff); +#endif + MQTTclient.publish("Arduino/Stall/data/Alive", buff); +#ifdef DEBUG + Serial.println("MQTT done"); +#endif + loopcnt = 1; + } + /* process incoming connections one at a time forever */ + webserver->processConnection(buff, &len); }