SHOW:
|
|
- or go back to the newest paste.
1 | #include <Adafruit_CC3000.h> | |
2 | #include <ccspi.h> | |
3 | #include <SPI.h> | |
4 | ||
5 | // Define CC3000 chip pins | |
6 | #define ADAFRUIT_CC3000_IRQ 3 | |
7 | #define ADAFRUIT_CC3000_VBAT 5 | |
8 | #define ADAFRUIT_CC3000_CS 10 | |
9 | ||
10 | Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, | |
11 | SPI_CLOCK_DIV2); // you can change this clock speed but DI | |
12 | ||
13 | #define WLAN_SSID "WIFI SSID" // cannot be longer than 32 characters! | |
14 | #define WLAN_PASS "WIFI PASSWORD" | |
15 | // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 | |
16 | #define WLAN_SECURITY WLAN_SEC_WPA2 | |
17 | ||
18 | Adafruit_CC3000_Client client; | |
19 | ||
20 | uint32_t ip = cc3000.IP2U32(192,168,1,14); | |
21 | ||
22 | ||
23 | void setup() | |
24 | { | |
25 | ||
26 | Serial.begin(115200); | |
27 | ||
28 | // Initialise the CC3000 module | |
29 | if (!cc3000.begin()) | |
30 | { | |
31 | while(1); | |
32 | } | |
33 | ||
34 | // Connect to WiFi network | |
35 | cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); | |
36 | Serial.println(F("Connected to WiFi network!")); | |
37 | ||
38 | // Check DHCP | |
39 | Serial.println(F("Request DHCP")); | |
40 | while (!cc3000.checkDHCP()) | |
41 | { | |
42 | delay(100); | |
43 | } | |
44 | ||
45 | String request = "[TIME]"; | |
46 | Serial.println(request); | |
47 | send_request(request); | |
48 | ||
49 | } | |
50 | ||
51 | void loop() | |
52 | { | |
53 | String request = "[TIME]"; | |
54 | Serial.println(request); | |
55 | send_request(request); | |
56 | delay(10000); | |
57 | } | |
58 | ||
59 | void send_request (String request) { | |
60 | ||
61 | // Connect | |
62 | Serial.println("Starting connection to server..."); | |
63 | Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 7286); | |
64 | ||
65 | // Send request | |
66 | if (client.connected()) { | |
67 | client.println(request); | |
68 | Serial.println("Connected & Data sent"); | |
69 | } | |
70 | else { | |
71 | Serial.println(F("Connection failed")); | |
72 | } | |
73 | ||
74 | while (client.connected()) { | |
75 | while (client.available()) { | |
76 | // Read answer | |
77 | Serial.print((char)client.read()); | |
78 | } | |
79 | } | |
80 | Serial.println("Closing connection"); | |
81 | Serial.println(""); | |
82 | client.close(); | |
83 | ||
84 | } |