Webserver only w/o any other functions, single thread. Running on STM32F013+W5500

Dependencies:   NTPClient W5500Interface Watchdog device_configuration eeprom_flash mbed-rpc-nucleo mbed-rtos mbed

Fork of F103-Serial-to-Ethernet by Chau Vo

Revision:
46:971bdaa3507c
Parent:
45:8d18a95fcf8a
Child:
47:d92d2c5b8073
diff -r 8d18a95fcf8a -r 971bdaa3507c main.cpp
--- a/main.cpp	Tue Jul 19 07:50:53 2016 +0000
+++ b/main.cpp	Sun Aug 14 11:06:53 2016 +0000
@@ -1,14 +1,14 @@
 #include "mbed.h"
 #include "rtos.h"
-#include "mbed_rpc.h"
+//#include "mbed_rpc.h"
 #include "Arguments.h"
 
-#include "eeprom.h"
 #include "EthernetInterface.h"
 #include "NTPClient.h"
+#include "Watchdog.h"
 
-#include "my_eeprom_funcs.h"
-#include "Watchdog.h"
+#include "eeprom_flash.h"
+#include "device_configuration.h"
 
 #include "RPCCommand.h"
 #include "HTTPServer.h"
@@ -34,7 +34,7 @@
 #define WARN(x, ...)
 #define ERR(x, ...)
 #endif
-
+                                
 
 /*
  * Hardware defines
@@ -44,206 +44,61 @@
 EthernetInterface eth(&spi, PA_4, PC_9); // spi, cs, reset
 int ethernet_init(void);
 
-/*
- * EEPROM section
- */
-// Virtual address defined by the user: 0xFFFF value is prohibited
-uint16_t VirtAddVarTab[NumbOfVar] = {0x1212, 0x1313, 0x1414, 0x1515, // IP_Addr
-                                     0x2212, 0x2313, 0x2414, 0x2515, // IP_Subnet
-                                     0x3212, 0x3313, 0x3414, 0x3515, // IP_Gateway
-                                     0x4212, // TCP server port, not used
-                                     0x5212, // UDP server port, not used
-                                     0x8888, // 1st run? 0xA5A5 = static IP has been configured
-                                     0x6212, 0x6313, 0x6414, // MAC
-
-                                     // this section is for the TCP server that this device connects to in TCP client mode
-                                     0x7212, 0x7313, // 0xA5A5 = auto transmit status, time period
-                                     0x8212, 0x8313,0x8414, 0x8515, // TCP server IP address
-                                     0x9212, // TCP server port
-
-                                     // this section is for selecting protocol, not used
-                                     0xA212, // 0xA5A5 = enable TCP server
-                                     0xA313, // 0xA5A5 = eanble TCP client
-                                     0xA414  // 0xA5A5 = enable UDP server, always enabled for configuration
-                                    };
-
-
-/*
- * Variables for network configuration, TCP server
- */
-// Device configuration
-uint16_t u16ip_addr[4], u16ip_subnet[4], u16ip_gateway[4], u16mac_addr[3]; // 16-bits variables to be compatible with eeprom functions
-char str_ip_addr[16], str_ip_subnet[16], str_ip_gateway[16], str_mac_addr[20]; // RPC variables, converted from 16-bits u16ip_xxx
-uint8_t u8ip_addr[4]; // keep ip address in 8-bits
-uint16_t configured_ip = 0;  // flag indicates a static ip has been configured 0xA5A5
-uint8_t u8mac[6]; // mac in 8-bits
-
-// TCP/UDP server
-uint16_t tcp_server_local_port = 10000; // change to 7000 if internet required
-uint16_t udp_server_local_port = 11000;
-
-// Used for TCP client mode
-// this section is used to set the TCP server that this device connects to in TCP client mode.
-// this device will update its status to the server every transmit_time_period.
-uint16_t auto_transmit_flag = 0, transmit_time_period = 1000; // auto transmit status, time period = 1s
-uint16_t u16server_ip_addr[4]; // 16-bit variable to be compatible with eeprom functions
-uint8_t u8server_ip_addr[4]; // server ip address in 8-bits
-char str_server_ip_addr[16]; // RPC variable, converted from 16-bits u16server_ip_addr
-uint16_t u16tcp_server_port; // 16-bit variable to be compatible with eeprom functions
-uint16_t u16enable_tcp_server, u16enable_tcp_client; // flags for enabling TCP client or TCP server
-
-// Corresponding RPC variables
-RPCVariable<char*> rpcIPAddress(str_ip_addr, 16, "ipaddr");
-RPCVariable<char*> rpcSubnet(str_ip_subnet, 16, "subnet");
-RPCVariable<char*> rpcGateway(str_ip_gateway, 16, "gateway");
-RPCVariable<char*> rpcMac(str_mac_addr, 20, "mac");
-//RPCVariable<unsigned short> rpcLocalTCPServerPort(&tcp_server_local_port, "localtcpserverport");
-RPCVariable<unsigned short> rpcLocalUDPPort(&udp_server_local_port, "localudpport");
-//RPCVariable<unsigned short> rpcEnableTCPServer(&u16enable_tcp_server, "enabletcpserver");
-
-// RPC function definitions
-// save ip address only
-void set_ip_addr(Arguments* args, Reply* rep){
-    int b[4], n, i;
-    char ipaddr[4];
-    
-    n = sscanf(str_ip_addr, "%d.%d.%d.%d", &b[0], &b[1], &b[2], &b[3]);
-    if (n == 4) {
-        DBG("%d.%d.%d.%d",b[0],b[1],b[2],b[3]);
-        for (i = 0; i < 4; i++) {
-            ipaddr[i] = b[i] & 0x00FF;
-        }
-        save_ip_addr(ipaddr);
-        NVIC_SystemReset();
-    }
-    else {
-        DBG("Saving IP address failed");
-    }
-}
-
-// set configuration flag
-void set_configuration_flag(Arguments* args, Reply* rep){
-    set_conf();
-}
-
-// reset configuration flag
-void reset_configuration_flag(Arguments* args, Reply* rep){
-    reset_conf();
-}
-
-// Attach eeprom functions to RPC functions
-RPCFunction rpcSaveIPAddr(&set_ip_addr, "saveipaddr");
-RPCFunction rpcSetConfiguration(&set_configuration_flag, "setconf");
-RPCFunction rpcResetConfiguration(&reset_configuration_flag, "resetconf");
+Serial pc(USBTX,USBRX);
+Watchdog wdt;
 
 
 /*
- * RPC Protocol
- * Use the RPC enabled wrapped class  - see RpcClasses.h for more info
+ * Variables for network configuration
  */
-// DigitalIn
-RpcDigitalIn di0(PB_14, "di0");
-RpcDigitalIn di1(PB_12, "di1");
-RpcDigitalIn di2(PB_10, "di2");
-RpcDigitalIn di3(PB_1, "di3");
-RpcDigitalIn di4(PB_15, "di4");
-RpcDigitalIn di5(PB_13, "di5");
-RpcDigitalIn di6(PB_11, "di6");
-RpcDigitalIn di7(PB_2, "di7");
-DigitalIn din0(PB_14);
-DigitalIn din1(PB_12);
-DigitalIn din2(PB_10);
-DigitalIn din3(PB_1);
-DigitalIn din4(PB_15);
-DigitalIn din5(PB_13);
-DigitalIn din6(PB_11);
-DigitalIn din7(PB_2);
-// DigitalOut
-RpcDigitalOut do0(PB_3, "do0");
-RpcDigitalOut do1(PB_5, "do1");
-RpcDigitalOut do2(PB_7, "do2");
-RpcDigitalOut do3(PB_9, "do3");
-RpcDigitalOut do4(PD_2, "do4");
-RpcDigitalOut do5(PB_4, "do5");
-RpcDigitalOut do6(PB_6, "do6");
-RpcDigitalOut do7(PB_8, "do7");
-DigitalOut dout0(PB_3);
-DigitalOut dout1(PB_5);
-DigitalOut dout2(PB_7);
-DigitalOut dout3(PB_9);
-DigitalOut dout4(PD_2);
-DigitalOut dout5(PB_4);
-DigitalOut dout6(PB_6);
-DigitalOut dout7(PB_8);
-// AnalogIn
-RpcAnalogIn adc10(PC_0, "ai0"); // adc10
-RpcAnalogIn adc11(PC_1, "ai1"); // adc11
-AnalogIn ain0(PC_0);
-AnalogIn ain1(PC_1);
-// AnalogOut, PWM
-RpcPwmOut pwm11(PA_8, "pwm0"); // pwm11
-RpcPwmOut pwm21(PA_15, "pwm1"); // pwm21
-// Serial
-RpcSerial rpcUsart(USBTX, USBRX, "uart"); // usart2
-Serial uart(USBTX,USBRX);
-// Timer
-RpcTimer timer1("tmr1");
-// Watchdog
-Watchdog wdt;
+// Device configuration
+extern uint16_t u16IpAddr[4], u16IpSubnet[4], u16IpGateway[4], u16MacAddr[3]; // 16-bits variables to be compatible with eeprom functions
+extern char strIpAddr[16], strIpSubnet[16], strIpGateway[16], strMacAddr[20]; // RPC variables, converted from 16-bits u16ip_xxx
+extern uint16_t u16DeviceConfiguredFlag;  // flag indicates whether device has been configured (0xA5A5) or not
+// TCP server/UDP
+extern uint16_t u16LocalTcpServerPort;
+extern uint16_t u16LocalUdpPort;
+// TCP client mode, set parameters of the remote TCP server this device connects to.
+// When enabled, this device will send its status to the server every transmit_time_period.
+extern uint16_t u16RemoteTcpServerIpAddr[4]; // 16-bit variable to be compatible with eeprom functions
+extern char strRemoteTcpServerIpAddr[16]; // RPC variable, converted from 16-bits u16server_ip_addr
+extern uint16_t u16RemoteTcpServerPort; // 16-bit variable to be compatible with eeprom functions
+extern uint16_t u16AutoTransmitFlag, u16TransmitPeriod; // auto transmit status, time period = 1s
+// enable modes
+extern uint16_t u16EnableTcpServer, u16EnableTcpClient, u16EnableUdp; // flags for enabling TCP server/client and UDP (UDP is always on for configuration)
+// extra
+extern uint8_t u8IpAddr[4]; // keep device ip address in 8-bits
+extern uint8_t u8MacAddr[6]; // keep mac in 8-bits
+extern uint8_t u8RemoteTcpServerIpAddr[4]; // remote TCP server ip address in 8-bits
 
 
-// Some variable types that can be modified through RPC.
-//int wheelsOn;
-//char lcdBannerMessage;
-//float speed;
-int current_time;
-int enable_onoff_dout = 0; // 8-bit LSB
-int do0OnTime = 64800, do0OffTime = 21600; //default ON = 18:00, OFF = 6:00
-int do1OnTime = 64800, do1OffTime = 21600;
-int do2OnTime = 64800, do2OffTime = 21600;
-int do3OnTime = 64800, do3OffTime = 21600;
-int do4OnTime = 64800, do4OffTime = 21600;
-int do5OnTime = 64800, do5OffTime = 21600;
-int do6OnTime = 64800, do6OffTime = 21600;
-int do7OnTime = 64800, do7OffTime = 21600;
- 
-//RPCVariable<int> rpcLights(&wheelsOn, "wheels");
-//RPCVariable<char> rpcBanner(&lcdBannerMessage, "banner");
-//RPCVariable<float> rpcSpeed(&speed, "speed");
-RPCVariable<int> rpcCurrentTime(&current_time, "Time");
-RPCVariable<int> rpcEnableOnOffDout(&enable_onoff_dout, "EnableOnOffDout");
-RPCVariable<int> rpcdo0OnTime(&do0OnTime, "do0OnTime");
-RPCVariable<int> rpcdo0OffTime(&do0OffTime, "do0OffTime");
-RPCVariable<int> rpcdo1OnTime(&do1OnTime, "do1OnTime");
-RPCVariable<int> rpcdo1OffTime(&do1OffTime, "do1OffTime");
-RPCVariable<int> rpcdo2OnTime(&do2OnTime, "do2OnTime");
-RPCVariable<int> rpcdo2OffTime(&do2OffTime, "do2OffTime");
-RPCVariable<int> rpcdo3OnTime(&do3OnTime, "do3OnTime");
-RPCVariable<int> rpcdo3OffTime(&do3OffTime, "do3OffTime");
-RPCVariable<int> rpcdo4OnTime(&do4OnTime, "do4OnTime");
-RPCVariable<int> rpcdo4OffTime(&do4OffTime, "do4OffTime");
-RPCVariable<int> rpcdo5OnTime(&do5OnTime, "do5OnTime");
-RPCVariable<int> rpcdo5OffTime(&do5OffTime, "do5OffTime");
-RPCVariable<int> rpcdo6OnTime(&do6OnTime, "do6OnTime");
-RPCVariable<int> rpcdo6OffTime(&do6OffTime, "do6OffTime");
-RPCVariable<int> rpcdo7OnTime(&do7OnTime, "do7OnTime");
-RPCVariable<int> rpcdo7OffTime(&do7OffTime, "do7OffTime");
+// Corresponding RPC variables
+RPCVariable<char*> rpcIPAddress(strIpAddr, 16, "ipaddr");
+RPCVariable<char*> rpcSubnet(strIpSubnet, 16, "subnet");
+RPCVariable<char*> rpcGateway(strIpGateway, 16, "gateway");
+RPCVariable<char*> rpcMac(strMacAddr, 20, "mac");
+RPCVariable<unsigned short> rpcLocalTCPServerPort(&u16LocalTcpServerPort, "localtcpserverport");
+RPCVariable<unsigned short> rpcLocalUDPPort(&u16LocalUdpPort, "localudpport");
+
+RPCVariable<unsigned short> rpcEnableTCPServer(&u16EnableTcpServer, "enabletcpserver");
+RPCVariable<unsigned short> rpcEnableTCPClient(&u16EnableTcpClient, "enabletcpclient");
+RPCVariable<unsigned short> rpcEnableUDP(&u16EnableUdp, "enableudp");
+
+RPCVariable<char*> rpcRemoteTCPServerIPAddress(strRemoteTcpServerIpAddr, 16, "remotetcpserveripaddr");
+RPCVariable<unsigned short> rpcRemoteTCPServerPort(&u16RemoteTcpServerPort, "remotetcpserverport");
+RPCVariable<unsigned short> rpcAutoTransmit(&u16AutoTransmitFlag, "autotransmit");
+RPCVariable<unsigned short> rpcTransmitPeriod(&u16TransmitPeriod, "transmitperiod");
 
 // RPC function definitions
-// Create a function of the required format
-void set_current_time(Arguments* args, Reply* rep);
-void set_current_time(Arguments* args, Reply* rep){
-    time_t ct = (time_t)current_time; // convert
-    struct tm *st = localtime(&ct);
-    
-    set_time(ct); // set time
-    
-    DBG("Set current time to: %s", ctime(&ct));
-    DBG("Time only: %d:%d:%d", st->tm_hour, st->tm_min, st->tm_sec);
+// save ip address only
+void show_device_config(Arguments* args, Reply* rep){
+    DBG("IP: %s", strIpAddr);
+    DBG("Subnet: %s", strIpSubnet);
+    DBG("Gateway: %s", strIpGateway);
+    DBG("MAC: %s", strMacAddr);
 }
-// Attach it to an RPC object
-RPCFunction rpcSetCurrentTime(&set_current_time, "SetTime");
-
+// Attach eeprom functions to RPC functions
+RPCFunction rpcShowConfig(&show_device_config, "showdevconf");
 
 /*
  * Threads
@@ -255,7 +110,6 @@
         wdt.Service();
 }
 
-
 HTTPServer create_simple_server()
 {    
     HTTPServer srv;
@@ -272,8 +126,6 @@
     return srv;
 }
 
-// Prototypes
-void digital_outputs_timer_thread(void const* args);
 
 // Main code
 int main()
@@ -283,31 +135,47 @@
     Thread::wait(500); // turn on delay
 
     /*
-    * Configure
-    */
-    uart.baud(115200);
+     * Configure
+     */
+    pc.baud(115200);
     DBG("Starting...");
 
     // check watchdog
     if (wdt.WatchdogCausedReset())
         DBG("Watchdog caused reset.");
     wdt.Configure(4);
-
+    
+    /*reset_device_configuration();
+    uint16_t ip[4] = {192,168,0,120};
+    uint16_t subnet[4] = {255,255,255,0};
+    uint16_t gateway[4] = {192,168,0,1};
+    uint16_t mac[3] = {0,0,1};
+    uint16_t tcp_port = DEFAULT_LOCAL_TCP_SERVER_PORT;
+    uint16_t udp_port = DEFAULT_LOCAL_UDP_PORT;
+    uint16_t remote_ip[4] = {0,0,0,0};
+    uint16_t remote_port = 12000;
+    uint16_t auto_transmit = DEFAULT_DISABLE_FLAG_VALUE;
+    uint16_t transmit_period = 1000;
+    uint16_t enable_tcp_server = DEFAULT_DISABLE_FLAG_VALUE;
+    uint16_t enable_tcp_client = DEFAULT_DISABLE_FLAG_VALUE;
+    uint16_t enable_udp = DEFAULT_ENABLE_FLAG_VALUE;
+    
+    write_device_configuration(ip, subnet, gateway, mac,
+            tcp_port, udp_port,
+            remote_ip, remote_port, auto_transmit, transmit_period,
+            enable_tcp_server, enable_tcp_client, enable_udp);*/
+    
+    read_device_configuration();
+    
+    
     /*
-    * FLASH
-    */
-    load_eeprom_network();
-    load_eeprom_tcpserver();
-
-    /*
-    * UI threads
-    */
-    Thread t3(wdt_reset_thread);
-    Thread t4(digital_outputs_timer_thread);
+     * UI threads
+     */
+    Thread t0(wdt_reset_thread);
     
     // rpc
     RPCType::instance().register_types();
-
+    
     /*
     * Ethernet
     */
@@ -318,7 +186,7 @@
     }
 
     Thread::wait(2000); // TCP/UDP stack delay
-
+    
     // create rpc http server
     HTTPServer srv = create_interactive_server();
 
@@ -328,10 +196,9 @@
         return -1;
     }
 
-    srv.run();
+    srv.run();  
 }
 
-
 /*
  * W5500 Ethernet init
  */
@@ -343,20 +210,20 @@
 
     // if not configured, try dhcp
     dhcp_ret = -1;
-    if (configured_ip != DEFAULT_ENABLE_FLAG_VALUE) {
+    if (u16DeviceConfiguredFlag != DEFAULT_ENABLE_FLAG_VALUE) {
         DBG("Connecting to DHCP server...");
-        dhcp_ret = eth.init(u8mac);
+        dhcp_ret = eth.init(u8MacAddr);
         if (dhcp_ret == 0)
             dhcp_ret = eth.connect();
     }
 
     if (dhcp_ret != 0) {
         DBG("No DHCP, load static IP configuration");
-        ret = eth.init(u8mac, str_ip_addr, str_ip_subnet, str_ip_gateway); // static
+        ret = eth.init(u8MacAddr, strIpAddr, strIpSubnet, strIpGateway); // static
     } else {
-        snprintf(str_ip_addr, 16, "%s", eth.getIPAddress());
-        snprintf(str_ip_subnet, 16, "%s", eth.getNetworkMask());
-        snprintf(str_ip_gateway, 16, "%s", eth.getGateway());
+        snprintf(strIpAddr, 16, "%s", eth.getIPAddress());
+        snprintf(strIpSubnet, 16, "%s", eth.getNetworkMask());
+        snprintf(strIpGateway, 16, "%s", eth.getGateway());
         ret = 0;
     }
 
@@ -378,372 +245,3 @@
     return 0;
 }
 
-// Timer thread to check on/off time of digital outputs
-void digital_outputs_timer_thread(void const* args)
-{
-    Thread::wait(700);
-    
-    while(true) {
-        // read current time
-        time_t seconds = time(NULL);
-        struct tm *st = localtime(&seconds);
-        int current_time_in_seconds = 3600*(st->tm_hour) + 60*(st->tm_min) + st->tm_sec;
-        DBG("Current time: %d:%d:%d", st->tm_hour, st->tm_min, st->tm_sec);
-        
-        // check do0
-        if ((enable_onoff_dout && 0x01) == 0x01) {
-            if (do0OnTime < do0OffTime) {
-                if ((current_time_in_seconds >= do0OnTime) && (current_time_in_seconds < do0OffTime)){
-                    if (dout0 == 0) {
-                        dout0 = 1;
-                        DBG("do0 ON");
-                    }
-                    else {
-                        DBG("do0 ON'ed");
-                    }
-                }
-                else {
-                    if (dout0 == 1) {
-                        dout0 = 0;
-                        DBG("do0 OFF'ed");
-                    }
-                    else {
-                        DBG("do0 OFF");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do0OffTime) && ((current_time_in_seconds < do0OnTime))) {
-                    if (dout0 == 1) {
-                        dout0 = 0;
-                        DBG("do0 OFF");
-                    }
-                    else {
-                        DBG("do0 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout0 == 0) {
-                        dout0 = 1;
-                        DBG("do0 ON");
-                    }
-                    else {
-                        DBG("do0 ON'ed");
-                    }
-                }
-            }
-        } // end check do0
-        
-        // check do1
-        if ((enable_onoff_dout && 0x02) == 0x02) {
-            if (do1OnTime < do1OffTime) {
-                if ((current_time_in_seconds >= do1OnTime) && (current_time_in_seconds < do1OffTime)){
-                    if (dout1 == 0) {
-                        dout1 = 1;
-                        DBG("do1 ON");
-                    }
-                    else {
-                        DBG("do1 ON'ed");
-                    }
-                }
-                else {
-                    if (dout1 == 1) {
-                        dout1 = 0;
-                        DBG("do1 OFF");
-                    }
-                    else {
-                        DBG("do1 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do1OffTime) && ((current_time_in_seconds < do1OnTime))) {
-                    if (dout1 == 1) {
-                        dout1 = 0;
-                        DBG("do1 OFF");
-                    }
-                    else {
-                        DBG("do1 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout1 == 0) {
-                        dout1 = 1;
-                        DBG("do1 ON");
-                    }
-                    else {
-                        DBG("do1 ON'ed");
-                    }
-                }
-            }
-        } // end check do1
-        
-        // check do2
-        if ((enable_onoff_dout && 0x04) == 0x04) {
-            if (do2OnTime < do2OffTime) {
-                if ((current_time_in_seconds >= do2OnTime) && (current_time_in_seconds < do2OffTime)){
-                    if (dout2 == 0) {
-                        dout2 = 1;
-                        DBG("do2 ON");
-                    }
-                    else {
-                        DBG("do2 ON'ed");
-                    }
-                }
-                else {
-                    if (dout2 == 1) {
-                        dout2 = 0;
-                        DBG("do2 OFF");
-                    }
-                    else {
-                        DBG("do2 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do2OffTime) && ((current_time_in_seconds < do2OnTime))) {
-                    if (dout2 == 1) {
-                        dout2 = 0;
-                        DBG("do2 OFF");
-                    }
-                    else {
-                        DBG("do2 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout2 == 0) {
-                        dout2 = 1;
-                        DBG("do2 ON");
-                    }
-                    else {
-                        DBG("do2 ON'ed");
-                    }
-                }
-            }
-        } // end check do2
-        
-        // check do3
-        if ((enable_onoff_dout && 0x08) == 0x08) {
-            if (do3OnTime < do3OffTime) {
-                if ((current_time_in_seconds >= do3OnTime) && (current_time_in_seconds < do3OffTime)){
-                    if (dout3 == 0) {
-                        dout3 = 1;
-                        DBG("do3 ON");
-                    }
-                    else {
-                        DBG("do3 ON'ed");
-                    }
-                }
-                else {
-                    if (dout3 == 1) {
-                        dout3 = 0;
-                        DBG("do3 OFF");
-                    }
-                    else {
-                        DBG("do3 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do3OffTime) && ((current_time_in_seconds < do3OnTime))) {
-                    if (dout3 == 1) {
-                        dout3 = 0;
-                        DBG("do3 OFF");
-                    }
-                    else {
-                        DBG("do3 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout3 == 0) {
-                        dout3 = 1;
-                        DBG("do3 ON");
-                    }
-                    else {
-                        DBG("do3 ON'ed");
-                    }
-                }
-            }
-        } // end check do3
-        
-        // check do4
-        if ((enable_onoff_dout && 0x10) == 0x10) {
-            if (do4OnTime < do4OffTime) {
-                if ((current_time_in_seconds >= do4OnTime) && (current_time_in_seconds < do4OffTime)){
-                    if (dout4 == 0) {
-                        dout4 = 1;
-                        DBG("do4 ON");
-                    }
-                    else {
-                        DBG("do4 ON'ed");
-                    }
-                }
-                else {
-                    if (dout4 == 1) {
-                        dout4 = 0;
-                        DBG("do4 OFF");
-                    }
-                    else {
-                        DBG("do4 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do4OffTime) && ((current_time_in_seconds < do4OnTime))) {
-                    if (dout4 == 1) {
-                        dout4 = 0;
-                        DBG("do4 OFF");
-                    }
-                    else {
-                        DBG("do4 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout4 == 0) {
-                        dout4 = 1;
-                        DBG("do4 ON");
-                    }
-                    else {
-                        DBG("do4 ON'ed");
-                    }
-                }
-            }
-        } // end check do4
-        
-        // check do5
-        if ((enable_onoff_dout && 0x20) == 0x20) {
-            if (do5OnTime < do5OffTime) {
-                if ((current_time_in_seconds >= do5OnTime) && (current_time_in_seconds < do5OffTime)){
-                    if (dout5 == 0) {
-                        dout5 = 1;
-                        DBG("do5 ON");
-                    }
-                    else {
-                        DBG("do5 ON'ed");
-                    }
-                }
-                else {
-                    if (dout5 == 1) {
-                        dout5 = 0;
-                        DBG("do5 OFF");
-                    }
-                    else {
-                        DBG("do5 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do5OffTime) && ((current_time_in_seconds < do5OnTime))) {
-                    if (dout5 == 1) {
-                        dout5 = 0;
-                        DBG("do5 OFF");
-                    }
-                    else {
-                        DBG("do5 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout5 == 0) {
-                        dout5 = 1;
-                        DBG("do5 ON");
-                    }
-                    else {
-                        DBG("do5 ON'ed");
-                    }
-                }
-            }
-        } // end check do5
-        
-        // check do6
-        if ((enable_onoff_dout && 0x40) == 0x40) {
-            if (do6OnTime < do6OffTime) {
-                if ((current_time_in_seconds >= do6OnTime) && (current_time_in_seconds < do6OffTime)){
-                    if (dout6 == 0) {
-                        dout6 = 1;
-                        DBG("do6 ON");
-                    }
-                    else {
-                        DBG("do6 ON'ed");
-                    }
-                }
-                else {
-                    if (dout6 == 1) {
-                        dout6 = 0;
-                        DBG("do6 OFF");
-                    }
-                    else {
-                        DBG("do6 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do6OffTime) && ((current_time_in_seconds < do6OnTime))) {
-                    if (dout6 == 1) {
-                        dout6 = 0;
-                        DBG("do6 OFF");
-                    }
-                    else {
-                        DBG("do6 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout6 == 0) {
-                        dout6 = 1;
-                        DBG("do6 ON");
-                    }
-                    else {
-                        DBG("do6 ON'ed");
-                    }
-                }
-            }
-        } // end check do6
-        
-        // check do7
-        if ((enable_onoff_dout && 0x80) == 0x80) {
-            if (do7OnTime < do7OffTime) {
-                if ((current_time_in_seconds >= do7OnTime) && (current_time_in_seconds < do7OffTime)){
-                    if (dout7 == 0) {
-                        dout7 = 1;
-                        DBG("do7 ON");
-                    }
-                    else {
-                        DBG("do7 ON'ed");
-                    }
-                }
-                else {
-                    if (dout7 == 1) {
-                        dout7 = 0;
-                        DBG("do7 OFF");
-                    }
-                    else {
-                        DBG("do7 OFF'ed");
-                    }
-                }
-            }
-            else {
-                if ((current_time_in_seconds >= do7OffTime) && ((current_time_in_seconds < do7OnTime))) {
-                    if (dout7 == 1) {
-                        dout7 = 0;
-                        DBG("do7 OFF");
-                    }
-                    else {
-                        DBG("do7 OFF'ed");
-                    }
-                }
-                else {
-                    if (dout7 == 0) {
-                        dout7 = 1;
-                        DBG("do7 ON");
-                    }
-                    else {
-                        DBG("do7 ON'ed");
-                    }
-                }
-            }
-        } // end check do7
-        
-        
-        // wait 1s
-        Thread::wait(10000); // Thread::wait() in ms
-    }
-}
\ No newline at end of file