Modifying version number for building on tizen 3.0
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SampleApp / arduino / Reference_Thing / src / oic_lanLib.cpp
1 /*
2  * oic_wifiLib.cpp
3  *
4  *  Created on: 2014. 11. 13.
5  *      Author: eunseok
6  */
7
8 #include "logger.h"
9 #include "ocstack.h"
10 #include <string.h>
11
12 // proximity code e
13 #ifdef ARDUINOWIFI
14 // Arduino WiFi Shield
15 #include <SPI.h>
16 #include <WiFi.h>
17 #include <WiFiUdp.h>
18 #else
19 // Arduino Ethernet Shield
20 #include <EthernetServer.h>
21 #include <Ethernet.h>
22 #include <Dns.h>
23 #include <EthernetClient.h>
24 #include <util.h>
25 #include <EthernetUdp.h>
26 #include <Dhcp.h>
27 #endif
28
29
30 PROGMEM const char TAG[] = "ReferenceSensor";
31
32 #ifdef ARDUINOWIFI
33 // Arduino WiFi Shield
34 // Note : Arduino WiFi Shield currently does NOT support multicast and therefore
35 // this server will NOT be listening on 224.0.1.187 multicast address.
36
37 /// WiFi Shield firmware with Intel patches
38 static const char INTEL_WIFI_SHIELD_FW_VER[] = "1.2.0";
39
40 /// WiFi network info and credentials
41 char ssid[] = "SoftSensor_AP";
42 char pass[] = "1234567890";
43 //char ssid[] = "SoftSensor_2.4G";
44 //char pass[] = "12344321";
45
46 int ConnectToNetwork()
47 {
48     char *fwVersion;
49     int status = WL_IDLE_STATUS;
50     // check for the presence of the shield:
51     if (WiFi.status() == WL_NO_SHIELD)
52     {
53         OC_LOG(ERROR, TAG, PCF("WiFi shield not present"));
54         return -1;
55     }
56
57     // Verify that WiFi Shield is running the firmware with all UDP fixes
58     fwVersion = WiFi.firmwareVersion();
59     OC_LOG_V(INFO, TAG, "WiFi Shield Firmware version %s", fwVersion);
60     if ( strncmp(fwVersion, INTEL_WIFI_SHIELD_FW_VER, sizeof(INTEL_WIFI_SHIELD_FW_VER)) !=0 )
61     {
62         OC_LOG(DEBUG, TAG, PCF("!!!!! Upgrade WiFi Shield Firmware version !!!!!!"));
63         return -1;
64     }
65
66     // attempt to connect to Wifi network:
67     while (status != WL_CONNECTED)
68     {
69         OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
70         status = WiFi.begin(ssid,pass);
71
72         // wait 10 seconds for connection:
73         delay(10000);
74     }
75     OC_LOG(DEBUG, TAG, PCF("Connected to wifi"));
76
77     IPAddress ip = WiFi.localIP();
78     OC_LOG_V(INFO, TAG, "IP Address:  %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
79     return 0;
80 }
81 #else
82 // Arduino Ethernet Shield
83 int ConnectToNetwork()
84 {
85     // Note: ****Update the MAC address here with your shield's MAC address****
86     uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x0E, 0xB8, 0xAC};
87
88     uint8_t error = Ethernet.begin(ETHERNET_MAC);
89     if (error  == 0)
90     {
91         OC_LOG_V(ERROR, TAG, "error is: %d", error);
92         return -1;
93     }
94     IPAddress ip = Ethernet.localIP();
95     OC_LOG_V(INFO, TAG, "IP Address:  %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
96     return 0;
97 }
98 #endif //ARDUINOWIFI