I am using Arduino Uno with Adafruit CC3000 wifi shield to connect to the internet and get data for Arduino. Everything works fine but I can't figure out how to use HttpClient library. The code is:
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <HttpClient.h>
#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_DIVIDER);
#define WLAN_SSID "ssid"
#define WLAN_PASS "pwd"
#define WLAN_SECURITY WLAN_SEC_WPA2
void setConnection(){
Serial.println("Initializing...");
if (!cc3000.begin())
{
Serial.println("Couldn't begin()! Check your wiring?");
while(1);
}
Serial.print("Attempting to connect to ");
Serial.println(WLAN_SSID);
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println("Failed!");
while(1);
}
Serial.println("Connected!");
Serial.println(F("Request DHCP"));
while (!cc3000.checkDHCP())
{
delay(100);
}
Serial.println(F("DHCP success!!"));
}
void dweet(){
int ctr=0;
char buff[100];
int x=0;
const char* host = "https://dweet.io/get/latest/dweet/for/dunebot";
Serial.println(F("Initializing dweet client ..."));
HttpClient client;
client.get(host);
Serial.println(F("Client Connected !"));
while (client.available()) {
char c = client.read();
Serial.write(c);
delay(100);
}
void setup(){
Serial.begin(115200);
while(!Serial);
Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
setConnection();
}
void loop(){
dweet();
}
If all worked fine then I should have got a json string which is:
{"this":"succeeded","by":"getting","the":"dweets","with":[{"thing":"dunebot","created":"2018-05-12T13:27:56.106Z","content":{"0001":""}}]}
When I run the code, Arduino connects to the wifi network but afterwards when I observe the Serial monitor all I get are garbage values.
I need a way to read the key 0001 from the json string. Any help would be appreciated.Thanks.