Page 2 sur 3

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 0:10
par G-Rom
le Wifi , du moment qu'on a une adresse et un port , c'est transparent non ?
Oui , je suis bête... j'ai regardé vite fait la doc, le shield permet bien de créer un serveur ou un client , bien lire la doc , car c'est pas les même capacité que son PC & PB hein :mrgreen:

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 13:17
par Dumli
Donc bilan des choses, pour transférer en WiFi l'appui d'une touche sur mon clavier à la Arduino, je dois :

PB (envoie l'info avec la lib réseau mais alors la lib Serial ne sert plus?) => Shield WiFi (réceptionne l'information WiFi) => Arduino (Lit l'info et exécute le code injecté au préalable) => Shield WiFi (renvoie l'info de confirmation) => PB (lit et affiche la confirmation)

Voilà ce que j'ai compris, par contre la lib Serial ne sert plus car on passe par le Réseau maintenant non ? :?

Après, je reste conscient qu'il faudra envoyer des infos lisibles par la Arduino notamment mettre des Delay() ... :roll:

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 16:36
par G-Rom
ton shield est autonome , plus besoin du serial. après qui fait le client / serveur... à toi de le définir.

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 16:41
par Dumli
Je pense que le plus logique au niveau optimisation serait de faire le serveur sur PC et le client la Arduino ou ça n'a rien à voir ? :roll:

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 16:46
par G-Rom
non, c'est ca.
Ton arduino ce connecte au pc en tant que client, je ne connais pas ton shield, je ne pourrais pas t'aider.

Re: SerialPort et WiFi

Publié : sam. 14/avr./2012 17:39
par Dumli
Ok, tu en as déjà fais beaucoup merci ! :wink:

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 16:25
par Dumli
Je ne parviens pas à faire fonctionner mon shield WiFi : Cupperhead. J'ai pourtant téléchargé la lib asynclab. J'ai pourtant suivi toutes les etapes suivantes :
  1. Download the software and put it into the right directory as described in the Software section above.
  2. Plug the WiShield into the Arduino board. Leave jumpers in default positions. The LED jumper (JP3) connected and the interrupt jumper (JP2) configured to use the INT0 pin.
  3. Restart the Arduino IDE to build the library and open the WebServer sketch from File->Sketchbook->Examples->Library->WiShield.
  4. The next step involves setting up the wireless configuration parameters like SSID and security for your wireless network. These parameters are defined at the top of the WebServer sketch.
  5. Find out the SSID of your wireless AP/router. You can get it by looking at the configuration setting of the wireless connection on laptop or by logging into you AP/router's config page.
  6. You need to figure out a good IP address to use for your WiShield. For this, you will have to find out the subnet mask and IP address range that your network uses. This can be found on a PC by right-clicking on the network connection icon at the bottom right corner of the taskbar and selecting 'Status'. Click on the Support tab. It might look something like,
    • IP address : 192.168.1.100
    • Subnet mask : 255.255.255.0
    • Default Gateway: 192.168.1.1
  7. We are only interested in getting a good IP address. What the subnet mask specifies is the network address. In the above case, the network address is 192.168.1.xxx and therefore all devices on this network will have IP addresses starting with '192.168.1'. This might be different for your AP. Since the current WiShield does not have support for DHCP you will have to select an IP address starting with this subnet mask. Just make sure you select something that is not used by any other device on your network.
  8. Change the local_ip variable in the sketch to your selected IP address. Change the ssid variable to your network SSID.
  9. The next step is to setup the right security options. The WiShield supports open (no security), WEP, WPA/TKIP-PSK, WPA2/AES-PSK. You might have to look at you AP/router configuration page to get this information unless you already know it. Change the security_type variable to select the appropriate security type. Depending on your security_type selection, you will now have to modify the security_passphrase/wep_keys variable to match you network settings.
  10. The sketch configures WiShield to connect to the AP (infrastructure mode) by default.
  11. The webpage[] array holds the webpage that this WebServer will serve up when requested.
  12. You are now all set to power up the WiShield. Compile the sketch and load it into the Arduino board.
  13. The red LED indicates connection status. Wait for the LED to turn on. The amount of time required to connect to the network varies depending on the security_type setting. If you selected open/WEP it should take 3/4 seconds to connect. If you selected WPA/WPA2, it takes slightly more than 30 seconds as the WiFi device needs to calculate the PSK from the passphrase for use in the security handshake.
  14. Once the red LED turns on, you are ready to talk to the device.
  15. You can try pinging the device by starting a terminal and typing,
    • $ ping <IP address of WiShield>
    • For example, $ ping 192.168.1.2 and you should see the WiShield respond to these ping requests
  16. If successful, fire up a browser and enter for example, http://192.168.1.2 and you should see the webpage displayed in your browser window.
  17. Now you are all set to be creative and come up with some interesting applications with the WiShield.
Je suis bloqué à l'étape 13, c'est-à-dire quand la LED WiFi-ON est censée s'allumer... :?

Voici mon code source :

Code : Tout sélectionner

/*
 * A simple sketch that uses WiServer to serve a web page
 */


#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,0,84};	// IP address of WiShield //J'ai mis une adresse IP qui est normalement libre
unsigned char gateway_ip[] = {10,25,217,210};	// router or gateway IP address //C'est l'adresse du routeur, je l'ai trouvé sur l'affiche de la FreeBox
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"JPPW"};		// max 32 bytes //SSID de mon WiFi

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

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"********"};	// max 64 characters // J'ai rentrer mon MDP wifi, je suis en WPA/WPA2 PSK

// 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 ----------------------------------------


// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("Hello World!");
        WiServer.print("</html>");
        
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){

  // Run WiServer
  WiServer.server_task();
 
  delay(10);
}

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 16:36
par G-Rom
Leave jumpers in default positions.
tu n'as pas oublier ce genre de détails ? ( p2 )
unsigned char gateway_ip[] = {10,25,217,210}; // router or gateway IP address //C'est l'adresse du routeur, je l'ai trouvé sur l'affiche de la FreeBox
t'es sur de ca ? l'ip de ma neuf box est 192.168.1.1
If you selected WPA/WPA2, it takes slightly more than 30 seconds as the WiFi device needs to calculate the PSK from the passphrase for use in the security handshake.
ta config doit être foireuse.

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 16:37
par Dumli
VICTOIRE !

Je viens de trouver la solution. En fait mon réseau est en WPA et pas en WPA 2 ... :!:

et encore merci G-Rom

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 16:44
par G-Rom
Impeccable , tu pourrais nous faire une démo de ce que tu fait avec ton arduino & ton shield ?

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 16:47
par Dumli
Oui pourquoi pas mais là nous sommes entrain de programmer donc pas avant ce soir :P

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 17:50
par Dumli
J'ai réussi à connecter la arduino au réseau WiFi par contre je ne parviens pas à la connecter au serveur créé en PureBasic sur mon PC. Pour l'instant le but est simple, j'essaie d'allumer la LED qui est sur la Arduino (pin 13) via le WiFi.
  • Coté Arduino, elle attend donc de recevoir une variable "data" et si cette varialble "data" = 1 alors elle allume la LED
    Coté PC (serveur), il crée le serveur et essaye d'envoyer l'info "data" à la Arduino (IP:192.168.0.84) et "data" a pour valeur 1
Code arduino :

Code : Tout sélectionner

#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,0,84};	// IP address of WiShield
unsigned char gateway_ip[] = {10,25,217,210};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the 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
// 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++));
  } 
}

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);
  
  pinMode(13, OUTPUT);
}


// 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) {
    getWeather.submit();    
    // Get another update one hour from now
    updateTime += 1000 * 60 * 60;
  }
  
  // Run WiServer
  WiServer.server_task();
 
  delay(10);
  
  if (Serial.available())
  {
    char data = Serial.read();
    switch (data)
    {
      case '1':
        digitalWrite(13, HIGH);
        delay(300);
        break;
      case '0':
        digitalWrite(13, LOW);
        delay(300);
        break;
    }
  }
}
Code PureBasic :

Code : Tout sélectionner

If InitNetwork() = 0
  MessageRequester("Error", "Can't initialize the network !", 0)
  End
EndIf

Port = 6832
*Buffer = AllocateMemory(1000)

If CreateNetworkServer(0, Port)

  MessageRequester("PureBasic - Server", "Server created (Port "+Str(Port)+").", 0)
  
  Repeat
      
    SEvent = NetworkServerEvent()
  
    If SEvent
    
      ClientID = EventClient()
  
      Select SEvent
      
        Case #PB_NetworkEvent_Connect
          MessageRequester("PureBasic - Server", "A new client has connected !", 0)
  
        Case #PB_NetworkEvent_Data
          MessageRequester("PureBasic - Server", "Client "+Str(ClientID)+" has send a packet !", 0)
          ReceiveNetworkData(ClientID, *Buffer, 1000)
          MessageRequester("Info", "String: "+PeekS(*Buffer), 0)
  
        Case #PB_NetworkEvent_File
          MessageRequester("PureBasic - Server", "Client "+Str(ClientID)+" has send a file via the network !", 0)
          ReceiveNetworkFile(ClientID, "C:\TEST_Network.ftp3")
  
        Case #PB_NetworkEvent_Disconnect
          MessageRequester("PureBasic - Server", "Client "+Str(ClientID)+" has closed the connection...", 0)
          Quit = 1
    
      EndSelect
    EndIf
    
    SendNetworkData(IPString("192.168.0.84"),,) ;J'essaie d'envoyer une donnée avec cette fonction à la Arduino qui a pour IP 192.168.0.84 mais je ne comprends pas quoi mettre dans le buffer et en longueur
    
  Until Quit = 1 
  
  MessageRequester("PureBasic - Server", "Click to quit the server.", 0)
  
  CloseNetworkServer(0)
Else
  MessageRequester("Error", "Can't create the server (port in use ?).", 0)
EndIf

End   
:|

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 18:48
par Backup
avec le meme code essaye en ayant le pc branché sur la prise reseau de ta box pour voir ?

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 19:05
par G-Rom
tu te connecte en wifi c'est une chose, mais le code arduino pour la connection tcp/ip est ou dans ton code ?
je ne vois rien se connecter sur le port 6832. 8O

Re: SerialPort et WiFi

Publié : mar. 17/avr./2012 21:10
par Dumli
Effectivement je comprends le soucis. En fait mon arduino est sur le réseau mais pas connecter au serveur créé par PB. J'ai donc cherché une solution pour connecter la Arduino au serveur et ainsi recevoir le message de confirmation dans PB "Client connected".
J'ai regardé un exemple Ethernet et ils utilisent :

Code : Tout sélectionner

byte mac[] = {0x00, 0x1E, 0xC0, 0x02, 0x8A, 0x0C};
byte ip[] = {192,168,0,84};
byte server[] = {192,168,0,47}; 

Client client(server, 6832); //C'est la qu'il y a un problème de compilation

Mais ça ne marche pas pour WiServer ... :roll: Je tourne en rond, de plus c'est impossible d'obtenir la liste des commandes pour les serveurs sur Arduino.

Y a t'il une commande pour se connecter à un serveur ?
Et quelle sont les commandes pour envoyer/recevoir des données, requestname.submit()/request.setReturnFunc(somefunctionname) ? :|

Merci