Help sending auth

Discussions related to the WiServer add-on code for WiShield. WiServer is a friendly, easy-to-use front end for webserver and webclient usages.

Moderator: shard7

Help sending auth

Postby selch » Sat Oct 23, 2010 8:57 pm

Hi all,

I'm new with the Arduino platform so please be gentle. I purchased and Arduino Uno and Wishield 2. I've successfully compiled and run the SimpleClient app, displaying the returned results in the serial monitor window. Now I'm trying to modify that app to hit a page that requires authentication. I've looked through the docs on WiShield involving char auth but I don't understand how to send that authentication.

My app:
Code: Select all
/*
* A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
* it via the Serial API
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Network"};      // max 32 bytes

unsigned char security_type = 3;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // Key 3
            };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------

// Function that prints data from the server
void printData(char* data, int len) {
 
  // Print the data returned by the server
  // Note that the data is not null-terminated, may be broken up into smaller packets, and
  // includes the HTTP header.
  while (len-- > 0) {
    Serial.print(*(data++));
  }
}

// IP Address for the site I want to hit 
uint8 ip[] = {11,11,11,11};

// Base64 encoded USERNAME:PASSWORD
char auth[] = "AOj5OmfYaWvz";

// A request that gets the data I want
GETrequest getPublicProd(ip, 80, "http://mysite.com", "/data.txt");

void setup() {
    // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages)
  WiServer.init(NULL);
 
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);

  // Have the processData function called when data is returned by the server
  getPublicProd.setReturnFunc(printData);
}


// Time (in millis) when the data should be retrieved
long updateTime = 0;

void loop(){

  // Check if it's time to get an update
  if (millis() >= updateTime) {
    getPublicProd.submit();   
    // Get another update one hour from now
    updateTime += 1000 * 60 * 60;
  }
 
  // Run WiServer
  WiServer.server_task();

  delay(10);
}


The result I get in the serial monitor is a 400 error from the webserver. I'm assuming that is because it's not authenticating. (IP addresses, user/pass, and site name changed to protect the innocent.)

Connected to http://mysite.com
TX 90 bytes
RX 0 bytes from http://mysite.com
RX 164 bytes from http://mysite.com
HTTP/1.0 400 Bad Request
Connection: close
Content-Type: text/html
Content-Length: 349
Date: Sun, 24 Oct 2010 03:01:17 GMT
Server: Vendor Proxy

<?xml versiRX 164 bytes from http://mysite.com
on="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
RX 164 bytes from http://mysite.com
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>400 - Bad Request</title>
</head>
<body>
<h1>400 - Bad Request</h1>
</bodyRX 10 bytes from http://mysite.com
>
</html>
Ended connection with http://mysite.com


It should returen a simple line of text along with the header info. Can someone please point me the way? I've been searching the forums and have found no examples that help explain this issue to me.

thanks!
selch
 
Posts: 2
Joined: Sat Oct 23, 2010 8:11 pm

Re: Help sending auth

Postby yba2cuo3 » Mon Oct 25, 2010 2:19 pm

// Base64 encoded USERNAME:PASSWORD
char auth[] = "AOj5OmfYaWvz";


Confirm that your authorization is correct. It doesn't look right to me. I find this site usefull when converting to Base64: http://www.motobit.com/util/base64-decoder-encoder.asp.

Marc
User avatar
yba2cuo3
 
Posts: 4
Joined: Wed Oct 20, 2010 7:09 am
Location: Ottawa, Ontario

Re: Help sending auth

Postby selch » Mon Oct 25, 2010 8:13 pm

yba2cuo3 wrote:
// Base64 encoded USERNAME:PASSWORD
char auth[] = "AOj5OmfYaWvz";


Confirm that your authorization is correct. It doesn't look right to me. I find this site usefull when converting to Base64: http://www.motobit.com/util/base64-decoder-encoder.asp.

Marc


The auth string is wrong. I didn't want to put out my real user/pass in the post.
selch
 
Posts: 2
Joined: Sat Oct 23, 2010 8:11 pm


Return to WiServer

Who is online

Users browsing this forum: No registered users and 1 guest