posting to using IP address

Hi, i have a couple of standard emonTx's running, but now i am trying to use Arduino+wifi to send data directly to I am using a CC3000 wifi shield with an Adafruit library, and it works for Xively. But when i post to i get a "408 Request Time-out". So i tried my json URL in my browser and noticed that it works fine when i use the hostname (which the Adafruit library does not allow me to do in the sketch), but not when i use the translated IP address:,281 >>WORKS (returns 'ok'),281 >>DOES NOT WORK (returns '404 not found')

This IP address is looked up by a library function. I tried the IP address mentioned here but same error.

Any ideas what i am doing wrong? Thanks in advance.


pb66's picture

Re: posting to using IP address

tomtobback's picture

Re: posting to using IP address

Thanks Paul, indeed that solves the issue in the browser.

Now next issue is that when i add this to my sketch, it still returns the '408 Request Time-out' so there must be something wrong in my code. I haven't found any examples of Adafruit's CC3000 library posting to so would be great if somebody could help. The format of the json seems correct becauseit works when i copy it from the Serial output into the browser. Just no clue why the GET request is not received on the server, causing the time-out.


String data = "";
  data = data + "/emoncms/input/post.json?" + "apikey=" + apikey + "&node=10" + "&csv=" + String(humidity) + "," + String(temperature) + "\0";  

  // Send request
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
      Serial.println("connection successfull, sending data.. ");
    // Make a HTTP request:
    client.println("GET " + data + " HTTP/1.1");
    client.println("Connection: close");
    Serial.println("GET request sent");
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed, will try again");
  // if there are incoming bytes available from the server, read them and print them:
  while (client.available()) {
    char c =;
    Serial.print(c);     // for debugging


pb66's picture

Re: posting to using IP address

It looks like your sketch is using www.emoncms,org AND /emoncms, that probably won't work, Have you tried replacing with the IP ?


or maybe even just dropping the www. (without the /emoncms)



tomtobback's picture

Re: posting to using IP address

Thanks Paul, i have tried the options but still getting the '408 Request Time-out' so it seems the server does not even receive the HTTP request. Below is my Serial Monitor output, with the exact HTTP request, maybe somebody sees what's wrong. Not a lack of memory it seems.

----Serial Monitor------------

FreeRam: 1200

Initializing CC3000...
Connected to WLAN!
Request DHCP ->
FreeRam: 1083
+++++++ HTTP request ++++++++++++++++++
GET /input/post.json?apikey=d66xxxx876a8&node=10&csv=571,281 HTTP/1.1
Connection: close

FreeRam: 843
TCP connection to successfull, sending above HTTP request..
GET request sent
FreeRam: 843
--------- HTTP reply  ----------------------------
HTTP/1.1 408 Request Time-out
Date: Wed, 17 Sep 2014 01:42:05 GMT
Server: Apache/2.2.22 (Ubuntu)
Vary: Accept-Encoding
Content-Length: 325
Connection: close
Content-Type: text/html; charset=iso-8859-1

<title>408 Request Time-out</title>
<h1>Request Time-out</h1>
<p>Server timeout waiting for the HTTP request from the client.</p>
<address>Apache/2.2.22 (Ubuntu) Server at Port 80</address>

Disconnecting from WLAN

tonypascal's picture

Re: posting to using IP address


I am also trying to make the CC3000 wifi shield post data. Could you please let me know where you found the code and provide it to me ?



Hayder's picture

Re: posting to using IP address


I have same problem, Any help please.




squiza's picture

Re: posting to using IP address

I would also love to find the answer to this problem.

i am trying to use an Arduino with hard wired ethernet to log optical pulses directly to the website. I am trying to avoid having to use an RF arrangement and dedicated base station.

snoopy's picture

Re: posting to using IP address

Anything new with this? What shield wifi or ethernet are you using to push data to website? 



lebritish's picture

Re: posting to using IP address

Hello to all,

Thanks to tomtobback I manage to post data to emoncms trough a CC3000 wifi shield.

You have to set a static IP to your shield first because DHCP is sooooooooooooooo long and rubbish.

However I am not using it anymore because the range of a CC3000 wifi shield is ridiculously short.

Anyway here is the code:



  This is an example for the Adafruit CC3000 Wifi Breakout & Shield

  Designed specifically to work with the Adafruit WiFi products:

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
This example does a test of the TCP client capability:
  * Initialization
  * Optional: SSID scan
  * AP connection
  * DHCP printout
  * DNS lookup
  * Optional: Ping
  * Connect to website and print out webpage contents
  * Disconnect
SmartConfig is still beta and kind of works but is not fully vetted!
It might not work on all networks!
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include <TimerOne.h>          // for software watchdog

#include "EmonLib.h"             // Include Emon Library


// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIVIDER); // you can change this clock speed

#define WLAN_SSID       "yournetwork "        // cannot be longer than 32 characters!
#define WLAN_PASS       "yourpassword"
// const char WLAN_PASS[] = {0xAA, 0xAA, 0xCC, 0xBB, 0xCC, 0x00}; for WEP encryption ONLY



#define IDLE_TIMEOUT_MS  3000      // Amount of time to wait (in milliseconds) with no data
                                   // received before closing the connection.  If you know the server
                                   // you're accessing is quick to respond, you can reduce this value.

// What page to grab!
#define WEBSITE      ""

uint32_t ip;

EnergyMonitor emon1;             // Create an instance

unsigned long starttime;
unsigned long sampletime_ms = 30000;   //time between sendind data minimum 30s ;
//last time the WDT was ACKd by the application
unsigned long lastUpdate=0;
 //time, in ms, after which a reset should be triggered
unsigned long timeout=60000;

void setup(void)
  emon1.voltage(1, 248, 1.77);  // Voltage: input pin, calibration, phase_shift
  emon1.current(0, 28.87);       // Current: input pin, calibration.
  lastUpdate=millis();        // start watchdog
  //Timer1.initialize(1000000); //1 second pulses
  Timer1.attachInterrupt(longWDT); //code to execute
  starttime = millis();               //get the current time;

void loop(void) {
   lastUpdate=millis();  // tell watchdog all is fine

   if ((millis()-starttime) > sampletime_ms)               //if the sample time == 30s
        emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
        emon1.serialprint();           // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
        float realPower       = emon1.realPower;        //extract Real Power into variable
        float apparentPower   = emon1.apparentPower;    //extract Apparent Power into variable
        float powerFactor     = emon1.powerFactor;      //extract Power Factor into Variable
        float supplyVoltage   = emon1.Vrms;             //extract Vrms into Variable
        float Irms            = emon1.Irms;             //extract Irms into Variable
    // at the end of one reading cycle, connect and post to website
  Serial.println(F("starting CC3000"));
  Serial.print("interval: "); Serial.println(starttime/1000);
  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
  /* Initialise the module */
  if (!cc3000.begin())
    Serial.println(F("Couldn't start CC3000! Check your wiring?"));
  Serial.print(F("Connecting to ")); Serial.println(WLAN_SSID);
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
   /* Optional: Set a static IP address instead of using DHCP.
     Note that the setStaticIPAddress function will save its state
     in the CC3000's internal non-volatile memory and the details
     will be used the next time the CC3000 connects to a network.
     This means you only need to call the function once and the
     CC3000 will remember the connection details.  To switch back
     to using DHCP, call the setDHCP() function (again only needs
     to be called once).
  /* //Your_network parameters
  uint32_t ipAddress = cc3000.IP2U32(192, 168, 2, 199);
  uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0);
  uint32_t defaultGateway = cc3000.IP2U32(192, 168, 2, 1);
  uint32_t dns = cc3000.IP2U32(192, 168, 1, 254);
  if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) {
    Serial.println(F("Failed to set static IP!"));
  /* Optional: Revert back from static IP addres to use DHCP.
     See note for setStaticIPAddress above, this only needs to be
     called once and will be remembered afterwards by the CC3000.
  if (!cc3000.setDHCP()) {
    Serial.println(F("Failed to set DHCP!"));

  /* Wait for DHCP to complete
  Serial.println(F("Requesting DHCP"));
  while (!cc3000.checkDHCP())
    delay(100); // ToDo: Insert a DHCP timeout!
  ip = 0;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
  /* Try connecting to the website.
     Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read.
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    www.fastrprint(F("GET "));
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
  } else {
    Serial.println(F("\nConnection failed"));    

  /* Read data until either the connection is closed, or the idle timeout is reached. */
  unsigned long lastRead = millis();
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c =;
      lastRead = millis();
  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time your try to connect ... */
  Serial.println(F("Disconnecting from CC3000"));
  starttime = millis();
  Serial.println(F("\n\nStarting a new sensor measurement"));

   @brief Begins an SSID scan and prints out all the visible networks
void listSSIDResults(void)
  uint32_t index;
  uint8_t valid, rssi, sec;
  char ssidname[33];

  if (!cc3000.startSSIDscan(&index)) {
    Serial.println(F("SSID scan failed!"));

  Serial.print(F("Networks found: ")); Serial.println(index);

  while (index) {

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.print(F("RSSI         : "));
    Serial.print(F("Security Mode: "));

   @brief Tries to read the IP address and other connection details

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;
    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);
    return true;

void (*resetFunc)(void) = 0;
void longWDT(void)
  if((millis()-lastUpdate) > timeout)
    //enable interrupts so serial can work
    //detach Timer1 interrupt so that if processing goes long, WDT isn't re-triggered
    //flush, as Serial is buffered; and on hitting reset that buffer is cleared
    Serial.println("WDT triggered");
    //call to bootloader / code at address 0


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.