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) 2020 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: 3.0
23
* Implementation: Yuri Carmona
24
*/
25
26
#include <WaspWIFI_PRO_V3.h>
27
28
uint8_t socket = SOCKET0;
29
uint8_t error;
30
uint8_t status;
31
unsigned long previous;
32
33
void setup()
34
{
35
USB.println(F("Start program"));
36
}
37
38
void loop()
39
{
40
//////////////////////////////////////////////////
41
// 1. Switch ON
42
//////////////////////////////////////////////////
43
error = WIFI_PRO_V3.ON(socket);
44
45
if (error == 0)
46
{
47
USB.println(F("1. WiFi switched ON"));
48
}
49
else
50
{
51
USB.println(F("1. WiFi did not initialize correctly"));
52
}
53
54
55
//////////////////////////////////////////////////
56
// 2. Join AP
57
//////////////////////////////////////////////////
58
59
// get actual time
60
previous = millis();
61
62
// check connectivity
63
status = WIFI_PRO_V3.isConnected();
64
65
// Check if module is connected
66
if (status == true)
67
{
68
USB.println(F("WiFi is connected OK"));
69
70
// ping
71
error = WIFI_PRO_V3.ping(ip_address);
72
73
// check response
74
if (error == 0)
75
{
76
USB.print(F("Ping sent packets = "));
77
USB.println(WIFI_PRO_V3._pingSent);
78
USB.print(F("Ping Received packets = "));
79
USB.println(WIFI_PRO_V3._pingReceived);
80
USB.print(F("Ping Lost packets = "));
81
USB.println(WIFI_PRO_V3._pingLost);
82
USB.print(F("Ping Total Time (ms) = "));
83
USB.println(WIFI_PRO_V3._pingTime);
84
USB.print(F("Ping Minimum Time (ms) = "));
85
USB.println(WIFI_PRO_V3._pingMinTime);
86
USB.print(F("Ping Maximum Time (ms) = "));
87
USB.println(WIFI_PRO_V3._pingMaxTime);
88
}
89
else
90
{
91
USB.println(F("Error calling 'ping' function"));
92
}
93
}
94
else
95
{
96
USB.println(F("WiFi is NOT connected"));
97
}
98
99
100
//////////////////////////////////////////////////
101
// 3. Switch OFF
102
//////////////////////////////////////////////////
103
WIFI_PRO_V3.OFF(socket);
104
USB.println(F("4. WiFi switched OFF\n\n"));
105
delay(10000);
106
}
Copied!
Last modified 5mo ago
Copy link