Code examples and extended information
In the Waspmote Development section you can find complete examples:
1
/*
2
* ------ WIFI Example --------
3
*
4
* Explanation: This example shows how to join an access point (AP)
5
*
6
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
7
* http://www.libelium.com
8
*
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
13
*
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
*
19
* You should have received a copy of the GNU General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
*
22
* Version: 0.1
23
* Design: David Gascon
24
* Implementation: Yuri Carmona
25
*/
26
27
#include <WaspWIFI_PRO.h>
28
29
uint8_t socket = SOCKET0;
30
uint8_t error;
31
uint8_t status;
32
unsigned long previous;
33
34
void setup()
35
{
36
USB.println(F("Start program"));
37
}
38
39
void loop()
40
{
41
//////////////////////////////////////////////////
42
// 1. Switch ON
43
//////////////////////////////////////////////////
44
error = WIFI_PRO.ON(socket);
45
46
if (error == 0)
47
{
48
USB.println(F("1. WiFi switched ON"));
49
}
50
else
51
{
52
USB.println(F("1. WiFi did not initialize correctly"));
53
}
54
55
56
//////////////////////////////////////////////////
57
// 2. Join AP
58
//////////////////////////////////////////////////
59
60
// get actual time
61
previous = millis();
62
63
// check connectivity
64
status = WIFI_PRO.isConnected();
65
66
// Check if module is connected
67
if (status == true)
68
{
69
USB.print(F("2. WiFi is connected OK."));
70
USB.print(F(" Time(ms):"));
71
USB.println(millis()-previous);
72
73
error = WIFI_PRO.ping("www.google.com");
74
75
if (error == 0)
76
{
77
USB.print(F("3. PING OK. Round Trip Time(ms)="));
78
USB.println( WIFI_PRO._rtt, DEC );
79
}
80
else
81
{
82
USB.println(F("3. Error calling 'ping' function"));
83
}
84
}
85
else
86
{
87
USB.print(F("2. WiFi is connected ERROR."));
88
USB.print(F(" Time(ms):"));
89
USB.println(millis()-previous);
90
}
91
92
93
//////////////////////////////////////////////////
94
// 3. Switch OFF
95
//////////////////////////////////////////////////
96
WIFI_PRO.OFF(socket);
97
USB.println(F("4. WiFi switched OFF\n\n"));
98
delay(10000);
99
}
Copied!
Last modified 1yr ago
Copy link