Buongiorno a tutti!
Faccio parte del tv-aug e da uno/due mesi mi sto cimentando con la wifi shield. (Con il grande e instancabile aiuto di Pitusso )
Allora io ho acquistato la wifi shield di futura elettronica e uso l'IDE 1.0
Il mio obbiettivo è aprire una socket tra il pc (in c#) e Arduino. PC---->AP---->Wifishield-arduino
Nella programmazione parte pc non ho problemi, al contrario del lato Arduino. Materiale in rete ce ne è poco per quanto riguarda la socket, ho fatto riferimento a questa pagina
per iniziare : Asynclabs.com
Purtroppo qui postano soltanto il codice da pc.
Qualcuno ha avuto esperienze con la socketapp? ad esempio come leggere o inviare dati?
Per farvi un resoconto, finora sono riuscito a connettermi con successo con una semplice applicazione in c# e al momento della connessione lo shield mi invia questi dati:
POST onnection with HTTP/1.0
Host: ÇÌ
Authorization: Basic
User-Agent: WiServer/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 6
2 [
già questo credo sia un'errore.
In sostanza non riesco a capire come modificare le librerie (se è necessario farlo) o il file socketapp.c e come ricevere e successivamente inviare dati dalla scheda.
vi posto il codice c#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace ProvaSocket
{
 public partial class Form1 : Form
 {
   TcpClient Connessione;
   NetworkStream Pippo;
   public Form1()
   {
     InitializeComponent();
   }
   private void Form1_Load(object sender, EventArgs e)
   {
   }
       private void button2_Click(object sender, EventArgs e)
   {
     Connessione = new TcpClient(); //inizializzo la connessione
     Connessione.Connect("192.168.1.2", 1000); //mi connetto
     Pippo = Connessione.GetStream();
     byte[] Ricevuti = new byte[300];
     Pippo.Read(Ricevuti, 0, 300); // leggo la risposta di arduino in un vettore di byte
     textBox2.Text = ConvertiInStringa(Ricevuti); //converto la risposta in una stringa e la vedo su una textbox ( il messaggio che ho postato prima )
   }
   private void button1_Click(object sender, EventArgs e)
   {
     //Connessione = new TcpClient("192.168.1.2", 1000);
     byte[] Dati = Encoding.ASCII.GetBytes(textBox1.Text);
//così trasformo le lettere che voglio inviare in un vettore di byte
     try
     {
       Pippo.Write(Dati, 0, Dati.Length); //invio il vettore di byte
     }
     catch (Exception send_exception)
     {
       textBox2.Text = "";
       textBox2.Text += " Exception " + send_exception.Message;
     }
   }
   string ConvertiInStringa(byte[] Vettore)
   {
     string appo = "";
     for (int i = 0; i < Vettore.Length; i++)
     {
       appo += (char)Vettore[i];
     }
     return appo;
   }
 }
e ora posto il codice di Arduino.
io ho inizializzato, avendo visto su un altro esempio, un vettore di char (credendo scioccamente che succeda qualcosa )
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/
#include <WiShield.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 = {"dd-wrt"};Â Â Â Â Â Â // 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 = {"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;
char buffer[20];
//---------------------------------------------------------------------------
void setup()
{
WiFi.init();
pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop()
{
   WiFi.run();
   if(buffer[0] == 65)
   {
    digitalWrite(7, HIGH);
    Serial.write(buffer[0]);
    Serial.write("\n");
   }
   else if(buffer[0]== 66)
   {
    digitalWrite(7, LOW);
    Serial.write(buffer[0]);
    Serial.write("\n");
   }
}
Questo è l'esempio di cui parlavo : TKJ Electronics » WiFi Controlled RC Car with the Arduino
Grazie a tutti, a presto