My Arduino Can't Go to localhost:3000/pir

Alright I have my WiFi shield set up, running REST API.

  This a simple example of the aREST Library for Arduino (Uno/Mega/Due/Teensy)
  using the CC3000 WiFi chip. See the README file for more details.
  Written in 2014 by Marco Schwartz under a GPL license. 

// Import required libraries
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <CC3000_MDNS.h>
#include <aREST.h>
#include <avr/wdt.h>

// These are the pins for the CC3000 chip if you are using a breakout board
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

#define pirPort 3000

// Create CC3000 instance  
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,

Adafruit_CC3000_Client client;

// Create aREST instance
aREST rest = aREST();

// Your WiFi SSID and password                                         
#define WLAN_SSID       "yourssid"
#define WLAN_PASS       "pw"

#define SERVER "led.local"
#define PAGE   "/pir"
#define HOME   "localhost"

char server[] = "localhost:3000";

// The port to listen for incoming TCP connections 
#define LISTEN_PORT           80

// Server instance
Adafruit_CC3000_Server restServer(LISTEN_PORT);

// DNS responder instance
MDNSResponder mdns;

// Variables to be exposed to the API

int localpin = 6;

void setup(void)
  // Start Serial
  // Init variables and expose them to REST API

  pinMode(6, INPUT);

  // Function to be exposed
  // Give name and ID to device
  // Set up CC3000 and get connected to the wireless network.
  if (!cc3000.begin())
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
  while (!cc3000.checkDHCP())
  // Print CC3000 IP address. Enable if mDNS doesn't work
  while (! displayConnectionDetails()) {
  // Start multicast DNS responder
  if (!mdns.begin("pir", cc3000)) {
  // Start server
  Serial.println(F("Listening for connections..."));

  // Enable watchdog


void loop() {
  // Handle any multicast DNS requests
  // Handle REST calls
  Adafruit_CC3000_ClientRef client = restServer.available();

  // Check connection, reset if connection is lost

// Print connection details of the CC3000 chip
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;

// Custom function accessible by the API
int pirStatus(String) {
  int state = digitalRead(6);
  if (state == 1) {
    Serial.print(F("Turn light on"));
  if (state == 0) {
      Serial.print(F("Turn light off"));
  return state;

int tcpSend(String) {
  unsigned long ip;
  Serial.print(F("Locating test server..."));
  cc3000.getHostByName((char *)server, &ip);
  do {
    client = cc3000.connectTCP(ip, 3000);
  } while (false);
  if(client.connected()) {
    Serial.print(F("OK\r\nIssuing HTTP request..."));
  if(cc3000.getHostByName("localhost", &ip)) {
    client.fastrprint(F("GET "));
    client.fastrprint(F(" HTTP/1.1\r\n"));
    client.fastrprint(F("Host: ")); client.fastrprint(HOME); client.fastrprint(F("\r\n"));
    Serial.println("Should work");
  } else {
    Serial.println(F("Connection failed"));    

int ledSend(String) {
  Serial.println("Performing HTTP GET of: ");
  client.println("GET /led/1 HTTP/1.1");
  client.println("Host: ");
  client.println("Connection: close");
  unsigned long ip;
  if(cc3000.getHostByName("led.local/led/1", &ip)) {
    client = cc3000.connectTCP(ip, 80);

But I can’t get the code to print past “Locating test server…” when I want the Arduino to GET localhost:3000/pir. I just want my Arduino to GET a webpage that I set up in localhost, but I’m not sure how the functionality or the entire library works. Does anyone know what I’m doing wrong?

localhost is just valid in terms of network when you want to refer to himself.For example the pc here you have apache installed can refer to his own web page via localhost but the arduino cannot do that because the page he tries to access it’s not in arduino itself(localhost is not valid here)
In other words you must set the ip address to the pc that is running apache, IIS …

I wanted to clarify a few points before I modified anything with the code. When you say I should replace "localhost" with the ip address, how would I replace them? I have the "localhost" defined in two places: do I just type in the ip address in one of them or both of them. And I am sure the Arduino cannot read " " well unless you have a constructor or class in mind that handles long integers with decimal points as an IP address. Also, the localhost server is running on Node, not Apache.

Let me understand, you have an arduino with a service running on port 3000 and you want acess it via localhost:3000? if yes why you want to do this?

Well I'm not sure if the Arduino is running on port 3000 unless I am doing something that is a unnecessary or code-breaking. But with the shield, I have the Arduino set up as a pir sensor, and I want to use the REST API to send data from the sensor to that localhost:3000/pir which holds my database and its running code to crunch numbers.

localhost is just that. It is a local host only on that computer.

You must use the localnet ip of the server, not localhost.

Maybe a bit of study on networking might be the thing for you.