|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- /*
- * struct.h
- *
- * Created on: 07.04.2020
- * Author: agr
- */
-
- #ifndef STRUCT_H_
- #define STRUCT_H_
-
-
-
- #include <PubSubClient.h>
- #include <Ethernet.h>
- #include <EEPROM.h>
-
- struct config_t
- {
- byte config_set;
- byte use_dhcp;
- byte dhcp_refresh_minutes;
- byte mac[6];
- byte ip[4];
- byte gateway[4];
- byte subnet[4];
- byte dns_server[4];
- unsigned int webserverPort;
- byte mqtt_server[4];
- unsigned int mqttserverPort;
- } eeprom_config;
-
- 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=1; // 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 MqttServer Port. In this case its Port 1883
- eeprom_config.mqttserverPort=1883;
-
- }
-
- #define P(name) static const unsigned char name[] __attribute__(( section(".progmem." #name) ))
-
- int EEPROM_readAnything(int ee, config_t& value)
- {
- byte* p = (byte*)(void*)&value;
- unsigned int i;
- for (i = 0; i < sizeof(value); i++)
- *p++ = EEPROM.read(ee++);
- return i;
- }
-
- int EEPROM_writeAnything(int ee, const config_t& value)
- {
- const byte* p = (const byte*)(const void*)&value;
- unsigned int i;
- for (i = 0; i < sizeof(value); i++)
- EEPROM.write(ee++, *p++);
- return i;
- }
-
- EthernetClient MQTTethClient;
- PubSubClient MQTTclient(MQTTethClient);
-
-
- #endif /* STRUCT_H_ */
|