/* * struct.h * * Created on: 07.04.2020 * Author: agr */ #ifndef STRUCT_H_ #define STRUCT_H_ #include #include #include 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_ */