1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
27 // Arduino WiFi Shield
32 // Arduino Ethernet Shield
33 #include <EthernetServer.h>
36 #include <EthernetClient.h>
38 #include <EthernetUdp.h>
43 PROGMEM const char TAG[] = "TrackeeSensor";
46 // Arduino WiFi Shield
47 // Note : Arduino WiFi Shield currently does NOT support multicast and therefore
48 // this server will NOT be listening on 224.0.1.187 multicast address.
50 /// WiFi Shield firmware with Intel patches
51 static const char INTEL_WIFI_SHIELD_FW_VER[] = "1.2.0";
53 /// WiFi network info and credentials
54 //char ssid[] = "SoftSensor_AP";
55 //char pass[] = "1234567890";
56 char ssid[] = "SoftSensor_2.4G";
57 char pass[] = "12344321";
59 int ConnectToNetwork()
62 int status = WL_IDLE_STATUS;
63 // check for the presence of the shield:
64 if (WiFi.status() == WL_NO_SHIELD)
66 OC_LOG(ERROR, TAG, PCF("WiFi shield not present"));
70 // Verify that WiFi Shield is running the firmware with all UDP fixes
71 fwVersion = WiFi.firmwareVersion();
72 OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
73 if ( strncmp(fwVersion, INTEL_WIFI_SHIELD_FW_VER, sizeof(INTEL_WIFI_SHIELD_FW_VER)) != 0 )
75 OC_LOG(DEBUG, TAG, PCF("!!!!! Upgrade WiFi Shield Firmware version !!!!!!"));
79 // attempt to connect to Wifi network:
80 while (status != WL_CONNECTED)
82 OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
83 status = WiFi.begin(ssid, pass);
85 // wait 10 seconds for connection:
88 OC_LOG(DEBUG, TAG, PCF("Connected to wifi"));
90 IPAddress ip = WiFi.localIP();
91 OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
95 // Arduino Ethernet Shield
96 int ConnectToNetwork()
98 // Note: ****Update the MAC address here with your shield's MAC address****
99 uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x0E, 0xB8, 0xAC};
101 uint8_t error = Ethernet.begin(ETHERNET_MAC);
104 OC_LOG_V(ERROR, TAG, "error is: %d", error);
107 IPAddress ip = Ethernet.localIP();
108 OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);