void net_beginService() { // initializes the W5100 and the TCP server for the user interface config_read(&cfg); uint8_t sn[4]={0}; //Init and config ethernet device w5100 W5100.init(); W5100.setMACAddress(cfg.mac); W5100.setIPAddress(cfg.ip); W5100.setGatewayIp(cfg.gw); toSubnetMask(cfg.subnet, sn); W5100.setSubnetMask(sn); printf_P(PSTR("ip: %u.%u.%u.%u/%u:%u\n\r"), cfg.ip[0], cfg.ip[1], cfg.ip[2], cfg.ip[3], cfg.subnet, cfg.port); printf_P(PSTR("subnet %u.%u.%u.%u\n\r"), sn[0], sn[1], sn[2], sn[3]); printf_P(PSTR("mac: %x:%x:%x:%x:%x:%x\n\r"), cfg.mac[0], cfg.mac[1], cfg.mac[2], cfg.mac[3], cfg.mac[4], cfg.mac[5]); printf_P(PSTR("gw: %u.%u.%u.%u\n\r"), cfg.gw[0], cfg.gw[1], cfg.gw[2], cfg.gw[3]); printf_P(PSTR("db: %u.%u.%u.%u:%u/%s\n\r"), cfg.ip_db[0], cfg.ip_db[1], cfg.ip_db[2], cfg.ip_db[3], cfg.port_db, cfg.name_db); printf_P(PSTR("cookie: %s\n\r"), cfg.cookie_db); printf_P(PSTR("function for inserting into DB: %s/%s\n\r"), cfg.doc_db, cfg.func_db); // Create the first server socket socket(FIRST_SERVER_SOCK, SnMR::TCP, cfg.port, 0); while(!listen(FIRST_SERVER_SOCK)){ // wait 100ms and try again wdt_delay_ms(100); } // connect to db, if do send to db // Create client to db // Port of the client can be arbitary, but it should be different then the port of ui server // connect_db(cfg.port+1); }
void beginService() { #ifdef EEPROM // TODO read eeprom #endif uint8_t sn[4]; //Init and config ethernet device w5100 W5100.init(); W5100.setMACAddress(cfg.mac); W5100.setIPAddress(cfg.ip); W5100.setGatewayIp(cfg.gw); toSubnetMask(cfg.subnet, sn); W5100.setSubnetMask(sn); // TODO reset client to db // Create the first server socket socket(0, SnMR::TCP, cfg.port, 0); serverSock[0] = W5100.readSnSR(0); while(!listen(0)){ // wait a second and try again _delay_ms(1000); } }