cuhead wifi shield v.2,0 comunication

Hi iv been trying to transfer data via wifi using my cuhead shield, i dont understand the code (sry, just started programming and usin arduino) there is 2 scetches, how do i get values etc between them?

iv manage to setup and connect to my nettwork and transfer the example data, but i want to transfer value, how do i add it to the code?

my code

/*
 * Socket App
 *
 * A simple socket application example using the WiShield 1.0
 */

#include <WiShield.h>
#include <socketapp.c>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

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

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

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"sikkerhet"};	// 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;
//---------------------------------------------------------------------------


void setup()
{
	WiFi.init();
int Led1 = 8;
pinMode(Led1,OUTPUT);

}

void loop()
{
	WiFi.run();

if(Val == 1){digitalWrite(Led1,HIGH);} //simply want to control this
if(Val == 0){digitalWrite(Led1,LOW);}

}

and the socketapp.c

/******************************************************************************

  Filename:		socketapp.c
  Description:	Simple socket programming example for the WiShield 1.0

 ******************************************************************************

  TCP/IP stack and driver for the WiShield 1.0 wireless devices

  Copyright(c) 2009 Async Labs Inc. All rights reserved.

  This program is free software; you can redistribute it and/or modify it
  under the terms of version 2 of the GNU General Public License as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59
  Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  Contact Information:
  <asynclabs@asynclabs.com>

   Author               Date        Comment
  ---------------------------------------------------------------
   AsyncLabs			06/06/2009	Initial version

 *****************************************************************************/

/*
 * This is a short example of how to write uIP applications using
 * protosockets.
 */

/*
 * We define the application state (struct socket_app_state) in the
 * socketapp.h file, so we need to include it here. We also include
 * uip.h (since this cannot be included in socketapp.h) and
 * <string.h>, since we use the memcpy() function in the code.
 */
#include "socketapp.h"
#include "uip.h"
#include <string.h>

/*
 * Declaration of the protosocket function that handles the connection
 * (defined at the end of the code).
 */
static int handle_connection(struct socket_app_state *s);
/*---------------------------------------------------------------------------*/
/*
 * The initialization function. We must explicitly call this function
 * from the system initialization code, some time after uip_init() is
 * called.
 */
void socket_app_init(void)
{
  /* We start to listen for connections on TCP port 1000. */
  uip_listen(HTONS(1000));
}
/*---------------------------------------------------------------------------*/
/*
 * In socketapp.h we have defined the UIP_APPCALL macro to
 * socket_app_appcall so that this function is uIP's application
 * function. This function is called whenever an uIP event occurs
 * (e.g. when a new connection is established, new data arrives, sent
 * data is acknowledged, data needs to be retransmitted, etc.).
 */
void socket_app_appcall(void)
{
  /*
   * The uip_conn structure has a field called "appstate" that holds
   * the application state of the connection. We make a pointer to
   * this to access it easier.
   */
  struct socket_app_state *s = &(uip_conn->appstate);

  /*
   * If a new connection was just established, we should initialize
   * the protosocket in our applications' state structure.
   */
  if(uip_connected()) {
    PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
  }

  /*
   * Finally, we run the protosocket function that actually handles
   * the communication. We pass it a pointer to the application state
   * of the current connection.
   */
  handle_connection(s);
}
/*---------------------------------------------------------------------------*/
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */


static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is you name?4balls\n");
  PSOCK_READTO(&s->p, '\n');
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, s->inputbuffer);
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);

  PSOCK_END(&s->p);
}

/*---------------------------------------------------------------------------*/

whats the difference of these two scetches? and why do i need both? how do i get a global value betwen both?
iv been searching all over the web and i cant find anything,

i know Val and Led placement is messed up, those are easy, its only the other stuff i need help with :slight_smile:

whats the difference of these two scetches?

What's the difference between a swimming pool and a banana? They have nothing in common that allows defining similarities or differences.

One is a sketch. One is a collection of functions used in the sketch.

and why do i need both?

Because the sketch calls the functions in the other file.

how do i get a global value betwen both?

A global variable is one that is accessible anywhere in the compilation unit. You only have one unit being compiled.

iv been searching all over the web and i cant find anything,

Can't find anything? That's hard to believe.

Can't figure out what to search for seems far more likely.

Now, what value from the socketapp.c file do you want to use in the sketch?

By the way, including the .c file in the sketch is very unusual. Typically, the .h file is included.

Hi thx for the reply!

What's the difference between a swimming pool and a banana?

banana is what i get every payday, and a svimminpool is something i wash myselfe in, preferably my neighbors pool.

there realy isnt any newb material on cuhead wifi shield on the nett, iv been searching all day, i wouldnt ask if i havnt tried everthing first.

all i want is to send a string,number or something i can communicate with, something like Serial.write(); Serial.read(); for arduino
and in processing recive the data with like port.read(); or port.print();

Mongoballe1:
there realy isnt any newb material on cuhead wifi shield on the nett, iv been searching all day, i wouldnt ask if i havnt tried everthing first.

Did you google "Arduino cuhead wifi shield"?
http://linksprite.com/wiki/index.php5?title=CuHead_WiFi_Shield_for_Arduino_V2.0

How you learn is entirely up to you, but may I suggest you start with simple tasks, and grow your program bit-by-bit? This will probably be more efficient, and you will learn the whole code - not just the parts that gives errors. Would've saved you a whole day of searching as well, learning absolutely nothing.

iv googled it in every single way possible (cuhead wifi shield commands/communicate/example/inventions/transfer/recive data/send data/ and so on

how am i suppost to learn it? it doesent say anywhere what the different commands mean?
iv read all the wiki pages and all the "apps" wishield etc in the library like 10 times or more., and half the commands in the example is black, im used to it beeing blue or something if it is a valid command.

no one knows? if i just got an example, like send a string og int and recive a string or int i could do the rest myselfe :.

i could do the rest myselfe

Given that you can't even spell, I have my doubts. Look at your last post. Read it carefully, looking at what's there, not what you think you put there. Does what is really there make any sense?

Paul:

Thats just mean

Put your dictionary away and read it one more time, use your head and some logic, if you dont understand what my question is or you dont have a answer DONT REPLY! Who mocks someone just because they have som bad spelling? Read your post CAREFULLY one more time, if you dont see that you just insulted me for no reason I advise you to take a social course. DO NOT doubt anyone you dont know, writing something like that to someone with maybe a low self esteem is so mean i cant even put it in words, luckily i dont have a low self esteem, Paul : think before you post.

English isnt my first language, and this isnt a spelling contest.

im sorry if my questions are stupid but as i recal Arduino is a hobby based product.

Mongoballe1:
iv googled it in every single way possible (cuhead wifi shield commands/communicate/example/inventions/transfer/recive data/send data/ and so on

how am i suppost to learn it? it doesent say anywhere what the different commands mean?
iv read all the wiki pages and all the "apps" wishield etc in the library like 10 times or more., and half the commands in the example is black, im used to it beeing blue or something if it is a valid command.

The answers you get reflects your own attitude. In your original post you excuse yourself for being new to Arduino - 2 posts later you have read everything 10 times.
When given a tip, take it or leave it. If necessary, ask questions - don't complain.
Be humble.
Read PaulS' first post one more time, ref bottom-part.
Read my post one more time, ref link.

Give information && ask questions || don't post.

The answers you get reflects your own attitude

im sorry if i had a bad attitude, i didnt intend to, i intended to be humble.

In your original post you excuse yourself for being new to Arduino - 2 posts later you have read everything 10 times.

im new to arduino meaning iv owned one one week, in that week iv read those pages 10 times (before you gave me the link), it only shows how to open the example and barely how it works, the example doesent explain how to send and recive commands, iv read the library files to, and they dont explain it either. But im gratefull for you taking your time to post it.

When given a tip, take it or leave it. If necessary, ask questions - don't complain.
Be humble.

if your refering to the "how am i suppost to learn it" part in my post, i didnt complain, i was asking.

Read PaulS' first post one more time, ref bottom-part.

Paul said

Now, what value from the socketapp.c file do you want to use in the sketch?

i said

all i want is to send a string,number or something i can communicate with, something like Serial.write(); Serial.read(); for arduino
and in processing recive the data with like port.read(); or port.print();

again i was not intending to be rude.

Read my post one more time, ref link.

you said

Did you google "Arduino cuhead wifi shield"?
http://linksprite.com/wiki/index.php5?title=CuHead_WiFi_Shield_for_Arduino_V2.0

How you learn is entirely up to you, but may I suggest you start with simple tasks, and grow your program bit-by-bit? This will probably be more efficient, and you will learn the whole code - not just the parts that gives errors. Would've saved you a whole day of searching as well, learning absolutely nothing.

as i said iv read it many times, i learn best by example, if i manage to send and recive something, i can learn from there, and thats what im asking for, without it its hard for me to learn.

I am grateful for all your answers, and for you taking your time to help me.

all i want is to send a string,number or something

Representing what? There must be something that the code is socketapp.c is doing that is interesting.

Representing what? There must be something that the code is socketapp.c is doing that is interesting.

The part where the comunication "begins" (at the bottom of socketapp.c)

/*---------------------------------------------------------------------------*/
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");                      // this part where it sends info and im able to recive it.
  PSOCK_READTO(&s->p, '\n');                                                                             // i dont quite understand this part, but it sems like  its reciving something, but im wondering where it stores it
 PSOCK_SEND_STR(&s->p, "Hello ");                                                                  
  PSOCK_SEND_STR(&s->p, s->inputbuffer);                                                   // iv seen inputbuffer being used in other code so what this means is interesting to.
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);                                                                                          //i dont want to close the com, i want to edit this out

  PSOCK_END(&s->p);                                                                                              // and edit this out to (i dont know if this is important)
}
/*---------------------------------------------------------------------------*/

iv commented the parts im interested in the code.

If i can get PSOCK_SEND_STR to send a variable from the first scetch
and PSOCK_READTO to read to a varable in the first scetch
as iv discovered they send a string (hello whats your name?\n) and recives a string (\n) (i cant figure out what \n is)
those are the main parts im interested in.

If i can get PSOCK_SEND_STR to send a variable from the first scetch

You can't send a variable. You can send the a value. You need to pass that value to the handle_connection() function. Then, instead of calling PSOCK_SEND_STR() with a hardcoded string, use sprintf() to construct the string, in a char array, and call PSOCK_SEND_STR() with that array as the second argument.

and PSOCK_READTO to read to a varable in the first scetch

Since the next two lines send "Hello " and the string that was entered in response to the first prompt, it should be obvious that the string that was entered is stored in the struct pointed to by s, in the inputbuffer member. Without knowing anything about how the struct is defined, it would be difficult to tell you how to convert the inputbuffer member to a value that can be returned. It looks like inputbuffer is a string, though, so atoi() or atof() could be used to convert the string to an int or a float, which the function could return.