Pages: 1 [2]   Go Down
Author Topic: Help with GET request?  (Read 1330 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

See, that's the problem. I have no idea why! It goes through and says "success" or whatever, but never ACTUALLY sends the GET request!

Your code:

Code:
if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");

Do you see "connected"?

Later:

Code:
 Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

Do you see "disconnecting"?

Don't just vaguely describe what you see. Copy and paste it.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Christ, I apologise, I just need a solution!
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"Apology accepted, Captain Needa".

Now what I need is for you to copy and paste your output.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tweaked the code a bit. Here is new output followed by new code.

Code:
|þþþþþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þÀ1þþ€Phone number:þÀ1þþ€Phone number:þÀ1þþ€Phone number:þÀ11þþ€Phone number:þÀ11þþ€Phone number:þÀ11þþ€Phone number:þÀ111þþ€Phone number:þÀ111þþ€Phone number:þÀ1111þþ€Phone number:þÀ1111þþ€Phone number:þÀ11111þþ€Phone number:þÀ11111þþ€Phone number:þÀ11111þþ€Phone number:þÀ111111þþ€Phone number:þÀ111111þþ€Phone number:þÀ111111þþ€Phone number:þÀ1111111þþ€Phone number:þÀ1111111þþ€Phone number:þÀ11111111þþ€Phone number:þÀ11111111þþ€Phone number:þÀ11111111þþ€Phone number:þÀ111111111þþ€Phone number:þÀ111111111þþ€Phone number:þÀ111111111þþ€Trolling option:þþ€Trolling option:þþ€Trolling option:þþ€Trolling option:þþ€Trolling option:þÀRickrollþþ€Connecting...connection failed


disconnecting.
==================

þÀGreat Success!þ€þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:þþ€Phone number:



Code:

#include <SPI.h>
#include <Ethernet.h>
#include <Keypad.h>
#include <EthernetClient.h>
const byte ROWS = 4;
const byte COLS = 3;
const int DELAY_VAL = 2;
const int MAX_SHIFT_VAL = 1023;
int buttonState = 0; // soft reset button state
String phoneNumber = "";
String clip = "";

char keys[ROWS][COLS] = {
   {'1','2','3'}
  ,{'4','5','6'}
  ,{'7','8','9'}
  ,{'*','0','#'}
}; // map out the keys

// map out the pins
byte rowPins[ROWS] = {5,6,7,8};
byte colPins[COLS] = {2,3,4};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

byte mac[] = { 0x90, 0xA2, 0xDA, 0x04, 0x00, 0x8D }; //physical mac address
byte subnet[] = {255,255,255,0};
byte gateway[] = {192,168,1,1};
char server[] = "www.api.tropo.com"; // zoomkat's test web page server

// instantiate a network client
EthernetClient client;

void setup()
{
  // start the serial library:
  Serial.begin(9600);
  // set display brightness
  Serial.write(0x7C);
  Serial.write(157);
  // set screen size in case LCD gets derpy...
  Serial.write(0xFE);
  Serial.write(6);
  Serial.write(0xFE);
  Serial.write(4);
  delay(4000);
  Ethernet.begin(mac, subnet, gateway);
  
  // start the Ethernet connection:
  // set up soft reset button

  ////attachInterrupt(0, softReset, CHANGE);
  // clear screen
  clearDisplay();
}

void loop()
{
  ////digitalWrite(softResetPin, LOW);
  // read the state of the reset button value:
  
  
  // check if the pushbutton is pressed (HIGH)
  
  
  delay(70); // delay loop to keep the LCD from redrawing stuff too much
  
 
  
  char keyPressed = keypad.getKey(); // need to check press selection on keypad

  if (keyPressed)
  {
    if (keyPressed == '#') // # and * are reveresed for some reason
    {
      clearDisplay();
      selectFirstLine();
      Serial.print("THE GAME");
      delay(500);
    }
    else if (keyPressed == '*')
    {
      clearDisplay();
      selectFirstLine();
      Serial.print("i said wut wut");
      selectSecondLine();
      Serial.print("in the *");
      delay(1000);
    }
    else
    {
      // check for complete number
      if (phoneNumber.length() == 10)
      {
        selectSecondLine();
        // determine which sound clip to play
        switch (keyPressed)
        {
        case '1':
          Serial.print("Rickroll");
          clip = "dfs";
          break;
        case '2':
          Serial.print("Nyan Cat");
          clip = "fds";
          break;
        case '3':
          Serial.print("Still Alive");
          clip = "fds";
          break;
        case '4':
          Serial.print("Hurr Durr");
          clip = "dfsfds";
          break;
        case '5':
          Serial.print("Heyyeahyeah");
          clip = "sdf";
          break;
        case '6':
          Serial.print("Friday");
          clip = "sfd";
          break;
        case '7':
          Serial.print("Tiny Tim");
          clip = "dfs";
          break;
        case '8':
          Serial.print("Banana Phone"); // OH GOD WHAT HAVE I DONE
          clip = "fsd";
          break;
        case '9':
          Serial.print("Britney Rant");
          clip = "dsf";
          break;
        }
        
        delay(3000);
      }
      else
      {
        phoneNumber = phoneNumber + keyPressed;
      }
    }
  }
  else
  {
    clearDisplay();
    if (phoneNumber.length() == 10)
    {
      if (clip == "")
      {
        selectFirstLine();
        Serial.print("Trolling option:");
      }
      else
      {
        selectFirstLine();
        Serial.print("Connecting...");
        // proceed to lulz
        sendGET();
        delay(10000);
        // close connection to ensure proper re-connect
        client.stop();
        selectSecondLine();
          Serial.print("Great Success!");
          selectFirstLine();
          delay(5000);
          phoneNumber = "";
          clip = "";
      }
    }
    else
    {
      selectFirstLine();
      Serial.print("Phone number:");
      
      if (phoneNumber.length() > 0)
      {
        selectSecondLine();
        Serial.print(phoneNumber);
      }
    }
  }
}

void clearDisplay() {
  Serial.write(0xFE);
  Serial.write(0x01);
}

void selectFirstLine() {
  Serial.write(0xFE);
  Serial.write(128);
   //delay(10);
}

void selectSecondLine() {
  Serial.write(0xFE);
  Serial.write(192);
}

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(server, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /1.0/sessions?action=create&token=fsdfd&number=fsdfds2 HTTP/1.0"); //download text
    client.println("Host: www.api.tropo.com");
    client.println(); //end of get request
  }
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}
« Last Edit: February 12, 2013, 11:20:35 pm by TheSpy7 » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What I see there that is relevant is this:

Code:
Connecting...connection failed


disconnecting.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What I see there that is relevant is this:

Code:
Connecting...connection failed


disconnecting.

Okay. So how do I fix the problem?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49035
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Okay. So how do I fix the problem?
There is nothing wrong with the code. The problem starts on the other end of the ethernet cable. You have not defined anything about that.

You have not said whether you are able to run the client example correctly. That would be a start.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Ethernet.begin(mac, subnet, gateway);

Wrong order of parameters, missing dns.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 144
Posts: 5974
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you read reply #13? It won't work until you call Ethernet.begin(mac) in the setup function.

edit: ...and called correctly.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay. So how do I fix the problem?

Uh, make it connect?
Logged


Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 51
Posts: 2273
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  // start the serial library:
  Serial.begin(9600);
  // set display brightness
  Serial.write(0x7C);
  Serial.write(157);
  // set screen size in case LCD gets derpy...
  Serial.write(0xFE);
  Serial.write(6);
  Serial.write(0xFE);
  Serial.write(4);

These Serial.writes will just produce garbage on the serial monitor. This is due to you having both the LCD and the monitor on Serial.

Code:
|þþþþþ€Phone number:þþ€Phone number:þþ

That accounts for the first group of garbage char's. The second and subsequent groups of garbage are coming from this
Code:
    }
    else
    {
      selectFirstLine();
      Serial.print("Phone number:");
     
      if (phoneNumber.length() > 0)
      {
        selectSecondLine();
        Serial.print(phoneNumber);
      }
 
I think, which means that phoneNumber has the crap in it. (or just maybe Serial.print() has a problem with String).
So and a debug statement to print out each key as you get it from the key pad i.e. in this bit of code
Code:
 
  delay(70); // delay loop to keep the LCD from redrawing stuff too much
 
 
 
  char keyPressed = keypad.getKey(); // need to check press selection on keypad

  if (keyPressed)
Logged

Pages: 1 [2]   Go Up
Jump to: