I'm currently trying to build an Arduino robot controlled via a wifi connection. I have an Arduino Mega running as a client and it successfully connects to the server on LAN via the Adafruit cc3000 wifi board. However instead of grabbing the contents of the JSON file and printing it to serial, I'm just getting a 100 continue response. While this means I'm doing something right, I don't know what to do next in order to grab the data I need. Do I need to get the 100 message then respond with the GET request, or is there a way that I can GET the data straight away?
Thank you all in advance. Here is the Arduino code I have so far:
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <stdlib.h>
// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5 // Apparently these can be any two pins
#define ADAFRUIT_CC3000_CS 10 // But I wouldn't change these...
// Use hardware SPI for the remaining pins (On a Mega 2560, SCK = 52, MISO = 50, and MOSI = 51)
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
#define WLAN_SSID "VM540258-2G"
#define WLAN_PASS "XXXXXXXX"
#define WLAN_SECURITY WLAN_SEC_WPA2
String readString = String(100); //string for fetching data from address
uint32_t ip = 3232235523; // This translates into the ip address we need
// 323223552X; 192.168.0.X
void setup(){
Serial.begin(115200); //Can also work at 9600
//Initialise CC3000 module
Serial.println(F("\nInitializing CC3000..."));
if (!cc3000.begin())
{
Serial.println(F("Couldn't begin()! Check your wiring?"));
while(1);
}
//Connect to the Wireless Access Point
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed!"));
while(1);
}
Serial.println(F("Connected!"));
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP()) { //Obtain IP addeess
delay(100);
}
while (! displayConnectionDetails())
{
delay(1000);
}
}
void loop(){
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {
client.println("GET /project-test/state.json HTTP/1.0"); //Make a request for state.json
client.println(""); //Mandatory blank line?
if (client.available()){
char c = client.read();
Serial.print(c);
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
}
}
}
//Once we have obtained the data, disconnect from the server
client.close();
Serial.println(readString);
delay(1000);
}
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}
The initial JSON file I'm using contains the following:
{"speed_left":null,"speed_right":null,"direction_left":null,"direction_right":null}
And the serial output I get when I run the Sketch:
Initializing CC3000...
Started AP/SSID scan
Connecting to VM540258-2G...Waiting to connect...Connected!
Request DHCP
IP Addr: 192.168.0.7
Netmask: 255.255.255.0
Gateway: 192.168.0.1
DHCPsrv: 192.168.0.1
DNSserv: 192.168.0.1
Connect to 192.168.0.3:80
100
Connect to 192.168.0.3:80
100
ad infinitum