Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_CC3000.h>
- #include <ccspi.h>
- #include <SPI.h>
- // Define CC3000 chip pins
- #define ADAFRUIT_CC3000_IRQ 3
- #define ADAFRUIT_CC3000_VBAT 5
- #define ADAFRUIT_CC3000_CS 10
- Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
- SPI_CLOCK_DIV2); // you can change this clock speed but DI
- #define WLAN_SSID "WIFI SSID" // cannot be longer than 32 characters!
- #define WLAN_PASS "WIFI PASSWORD"
- // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
- #define WLAN_SECURITY WLAN_SEC_WPA2
- Adafruit_CC3000_Client client;
- uint32_t ip = cc3000.IP2U32(192,168,1,14);
- void setup()
- {
- Serial.begin(115200);
- // Initialise the CC3000 module
- if (!cc3000.begin())
- {
- while(1);
- }
- // Connect to WiFi network
- cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
- Serial.println(F("Connected to WiFi network!"));
- // Check DHCP
- Serial.println(F("Request DHCP"));
- while (!cc3000.checkDHCP())
- {
- delay(100);
- }
- String request = "[TIME]";
- Serial.println(request);
- send_request(request);
- }
- void loop()
- {
- String request = "[TIME]";
- Serial.println(request);
- send_request(request);
- delay(10000);
- }
- void send_request (String request) {
- // Connect
- Serial.println("Starting connection to server...");
- Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 7286);
- // Send request
- if (client.connected()) {
- client.println(request);
- Serial.println("Connected & Data sent");
- }
- else {
- Serial.println(F("Connection failed"));
- }
- while (client.connected()) {
- while (client.available()) {
- // Read answer
- Serial.print((char)client.read());
- }
- }
- Serial.println("Closing connection");
- Serial.println("");
- client.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement