SocketAPP WiShield


salut tout le monde  :)

je rencontre des difficultés avec mon wishield (copperhead pour être exact) donc je viens faire appel à votre savoir  :smiley-mr-green: je voudrais envoyer une information en wifi à ma carte arduino uno r2 quand j'appui sur une touche de mon clavier. pour le moment je fais simple, j'ai fais un petit programme en python qui envoi succesivement les valeurs 1, 2, 3, ..., 6 et un autre programme sur la arduino qui interprète ces valeurs. la arduino recoit bien les données puisque dans le "serial monitor" je vois les messages mais on dirait qu'elle n'arrive pas à commander les pin quand le wishield est branché  :smiley-eek:

j'ai beau chercher, je ne comprends pas mon erreur  :smiley-slim:

voici les codes :

serveur python :
code: [select]
#!/usr/bin/python

import socket
import time

host = '192.168.0.100'     # remote host
port = 1000               # same port used server

def sendvalue(value):
  s = socket.socket(socket.af_inet, socket.sock_stream)
  s.connect((host, port))
  s.send(str(value) + '\n')
  s.close()

sendvalue(1)
time.sleep(1)
sendvalue("1")

sendvalue(2)
time.sleep(1)
sendvalue("2")

sendvalue(3)
time.sleep(1)
sendvalue("3")

sendvalue(4)
time.sleep(1)
sendvalue("4")

sendvalue(5)
time.sleep(1)
sendvalue("5")

sendvalue(6)
time.sleep(1)
sendvalue("6")


programme arduino "socket.pde":
code: [select]
/*
* socket app
*
* simple socket application example using wishield 1.0
*/

#include <wishield.h>

//wireless configuration defines ----------------------------------------
#define wireless_mode_infra   1
#define wireless_mode_adhoc   2

//wireless configuration parameters ----------------------------------------
unsigned char local_ip[]       = {
 192,168,0,100};  // ip address of wishield
unsigned char gateway_ip[]     = {
 192,168,0,47};     // router or gateway ip address
unsigned char subnet_mask[]    = {
 255,255,255,0}; // subnet mask local network
const prog_char ssid[] progmem = {
 "jppw"};    // max 32 bytes
unsigned char security_type    = 2;               // 0 - open; 1 - wep; 2 - wpa; 3 - wpa2
// wpa/wpa2 passphrase
const prog_char security_passphrase[] progmem = {
 "****************"};   // max 64 characters
// wep 128-bit keys
prog_uchar wep_keys[] progmem = {
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // 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 wireless mode
// infrastructure - connect ap
// adhoc - connect wifi device
unsigned char wireless_mode = wireless_mode_infra;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// end of wireless configuration parameters ----------------------------------------

char recvchar;

void setup()
{
 //set serial communications
 serial.begin(9600);
 pinmode(4, output);

 //set global recvchar indicate nothing received
 recvchar = null;
 wifi.init();
}

void loop()
{
 if(null != recvchar) {
   serial.print("received: ");
   serial.print(recvchar);
   serial.print(" [");

   switch(recvchar) {
   case '1':
     serial.println("forward]");
     //your control code goes here...
     digitalwrite(4, high);
     serial.println("commande envoyée");
     delay(300);
     break;
   case '2':
     serial.println("backward]");
     //your control code goes here...
     break;
   case '3':
     serial.println("turn right]");
     //your control code goes here...
     break;
   case '4':
     serial.println("turn left]");
     //your control code goes here...
     break;
   case '5':
     serial.println("stop]");
     //your control code goes here...
     break;
   default:
     serial.println("unexpected value received]");
     //your control code goes here...
     break;
   }

   //we have handled last data receive clear recvchar don't handle same data again.
   recvchar = null;
 }

 wifi.run();
}


programme arduino "socket.c"
code: [select]
/******************************************************************************

 filename:      socketapp.c
 description:   simple socket programming example wishield 1.0

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

 tcp/ip stack , driver wishield 1.0 wireless devices

 copyright(c) 2009 async labs inc. rights reserved.

 this program free software; can redistribute and/or modify it
 under terms of version 2 of gnu general public license as
 published free software foundation.

 this program distributed in hope useful, without
 any warranty; without implied warranty of merchantability or
 fitness particular purpose.  see gnu general public license for
 more details.

 you should have received copy of gnu general public license along with
 this program; if not, write 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

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

/*
* short example of how write uip applications using
* protosockets.
*/

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

extern char recvchar;

/*
* declaration of protosocket function handles connection
* (defined @ end of code).
*/
static int handle_connection(struct socket_app_state *s);
/*---------------------------------------------------------------------------*/
/*
* initialization function. must explicitly call function
* system initialization code, time after uip_init() is
* called.
*/
void socket_app_init(void)
{
  /* start listen connections on tcp port 1000. */
  uip_listen(htons(1000));
}
/*---------------------------------------------------------------------------*/
/*
* in socketapp.h have defined uip_appcall macro to
* socket_app_appcall function uip's application
* function. function called whenever uip event occurs
* (e.g. when new connection established, new data arrives, sent
* data acknowledged, data needs retransmitted, etc.).
*/
void socket_app_appcall(void)
{
  /*
   * uip_conn structure has field called "appstate" holds
   * application state of connection. make pointer to
   * access easier.
   */
  struct socket_app_state *s = &(uip_conn->appstate);

  /*
   * if new connection established, should initialize
   * protosocket in our applications' state structure.
   */
  if(uip_connected()) {
     psock_init(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
  }

  /*
   * finally, run protosocket function handles
  * communication. pass pointer application state
  * of current connection.
  */
  handle_connection(s);
}
/*---------------------------------------------------------------------------*/
/*
* protosocket function handles communication. a
* protosocket function must return int, must never
* explicitly return - return statements hidden in psock
* macros.
*/
static int handle_connection(struct socket_app_state *s)
{
  if(uip_newdata()) {
     psock_begin(&s->p);
     psock_readto(&s->p, '\n');
     recvchar = s->inputbuffer[0];
     psock_close(&s->p);
     psock_end(&s->p);
  }
  else {
     //if no new data received set our global 0 indicate no new data
     recvchar = null;
  }
}
/*---------------------------------------------------------------------------*/


merci d'avance  :)

bonjour, je n'ai pas compris ton erreur.. tu reçois bien tes valeurs mais.. la je bloque .. " mais on dirait qu'elle n'arrive pas à commander les pin quand le wishield est branché  "..? sa doit réagir et ça marche pas c'est ça??

skizo !


Arduino Forum > International > Français (Moderators: jfs, Snootlab) > SocketAPP WiShield


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial