OpenDevice
Open IoT (Internet Of Things) Platform and Framework http://opendevice.io
config.h
1 /*
2  * ******************************************************************************
3  * Copyright (c) 2013-2014 CriativaSoft (www.criativasoft.com.br)
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Ricardo JL Rufino - Initial API and Implementation
11  * *****************************************************************************
12  */
13 
14 #ifndef OPENDEVICE_CONFIG_H_
15 #define OPENDEVICE_CONFIG_H_
16 
17 #include <Arduino.h>
18 #include <EEPROM.h>
19 
20 // #if defined(__COMPILING_AVR_LIBC__)
21 // #include <avr/eeprom.h>
22 // #endif
23 
24 #ifndef __cplusplus
25 #error A C++ compiler is required!
26 #endif
27 
28 // =====================================
29 // STATIC CONFIGURATION
30 // =====================================
31 
32 #ifndef DEBUG
33 #define DEBUG 1
34 #endif
35 
36 #define DEBUG_SETUP 1 // set 1 to enable (receiving debug)
37 #define DEBUG_CON 0 // set 1 to enable (receiving debug)
38 #define ENABLE_SERIAL 1
39 
40 #define API_VERSION 050 // software version of this library
41 #define CONFIG_VERSION "cv1" // version of config layout
42 #define CONFIG_START 0 // start address in EEPROM
43 
44 #define DEFAULT_BAUD 115200
45 #define DEFAULT_SERVER_PORT 8182 // Used only in server mode to receive socket connections
46 #define DISCOVERY_PORT 6142 // UDP port to enable discovery services.
47 #define KEEP_ALIVE_INTERVAL 30000
48 #define KEEP_ALIVE_MAX_MISSING 3
49 #define ENABLE_DEVICE_INTERRUPTION 0
50 #define ENABLE_SYNC_DEVICEID 1 // Sync DeviceID from server and save on EEPROM.
51 #define ENABLE_PREFIX_NAME 1 // Add Module name to Devices
52 #define LOAD_DEVICE_STORAGE 0 // Load deviceID from EEPROM ? (enable in production)
53 
54 #define RECONNECT_TIMEOUT 30000
55 
56 // #define ENABLE_REMOTE_WIFI_SETUP 0 // disable to reduce flash usage
57 #define ENABLE_SSL 0 // disable to reduce flash/memory usage (tested only for MQTT/ESP8266)
58 #define ENABLE_ALEXA_PROTOCOL 0 // Enable Alexa/AmazonEcho direct integration (ESP8266 Only)
59 #define ALEXA_MAX_DEVICES 10 // MAX 14
60 
61 #ifndef ENABLE_DHCP
62 #define ENABLE_DHCP 1 /* if you need save flash memory disable this
63  Another important config to save flash memory is disable UDP of UIPEthernet (UIPEthernet/utility/uipethernet-conf.h) */
64 #endif
65 
66 #define MAX_DEVICE_ID 255
67 
68 // ---- Low Memory Devices ----------
69 #if defined(__AVR_ATtinyX313__) || defined(__AVR_ATtinyX4__) || defined(__AVR_ATtinyX5__)
70 #define DATA_BUFFER 16
71 #define MAX_DEVICE_NAME 10
72 #define MAX_LISTENERS 2
73 #define MAX_DEVICE 5
74 
75 #define MAX_COMMAND 5 // this is used for user command callbacks
76 #define MAX_COMMAND_STRLEN 5
77 #define READING_INTERVAL 100 // sensor reading interval (ms)
78 
79 // ---- High Memory Devices --------
80 #elif defined(ESP8266)
81 #define DATA_BUFFER 256
82 #define MAX_LISTENERS 5
83 #define MAX_DEVICE 20
84 #define MAX_DEVICE_NAME 25
85 #define MAX_COMMAND 5 // this is used for user command callbacks
86 #define MAX_COMMAND_STRLEN 14
87 #define READING_INTERVAL 100 // sensor reading interval (ms)
88 
89 // ---- Medium Memory Devices --------
90 #else
91 #define DATA_BUFFER 128
92 #define MAX_LISTENERS 5
93 #define MAX_DEVICE 10
94 #define MAX_DEVICE_NAME 25
95 #define MAX_COMMAND 3 // this is used for user command callbacks
96 #define MAX_COMMAND_STRLEN 14
97 #define READING_INTERVAL 100 // sensor reading interval (ms)
98 
99 #endif
100 
101 
102 // May be better use: https://github.com/mrRobot62/Arduino-logging-library OU -VDEBUG(see ESP8266)
103 enum DebugTarget{
104  DEBUG_SERIAL,
105  DEBUG_CURRENT
106 };
107 
108 enum ConnectionMode{
109  CONNECTION_MODE_CLIENT,
110  CONNECTION_MODE_SERVER
111 };
112 
113 
114 // =====================================
115 // DYNAMIC CONFIGURATION
116 // =====================================
117 
118 namespace od {
119 
123  struct ConfigClass{
124 
125  char version[4]; // version of config - used for validation
126  char moduleName[15];
127  char server[25];
128  char appID[36]; // ApiKey
129  byte id[6]; // MAC
130  byte ip[4];
131  uint8_t pinReset;
132  bool debugMode;
133  bool keepAlive;
134  uint8_t debugTarget;
135  uint8_t connectionMode;
136  int8_t devicesLength;
137  uint16_t devices[MAX_DEVICE];
138 
139  void load();
140  void save();
141  void clear();
142  bool check();
143 
144  };
145 
146  extern ConfigClass Config;
147 }
148 
149 
150 #endif /* OPENDEVICE_CONFIG_H_ */
Definition: config.cpp:3
void clear()
Definition: config.cpp:56
Definition: config.h:123
void load()
Definition: config.cpp:26
void save()
Definition: config.cpp:46
bool check()
Definition: config.cpp:39