aide pour code girouette avec un shield ethernet

Bonjour

Je possède une girouette avec laquelle je suis capable de connaitre l'orientation du vent à partir du moniteur série.
Je voudrais envoyer ces informations sur un site web grâce à mon shield ethernet.
J'ai un code me permettant de créer un serveur web mais je n'arrive pas à combiner les 2 codes (code de la girouette et du shield) pour avoir l'orientation du vent sur mon serveur.

Comment faire?

code de la girouette :

// Reference la librairie I2C
#include <Wire.h>
// Reference la librairie de la boussole HMC5883L 
#include <HMC5883L.h>

// déclare notre boussole comme une variable.
HMC5883L compass;
// Enregistre toute erreur provoquée par la boussole.
int error = 0;

// Configuration de la boussole et du microcontroleur 
void setup()
{
  // Initialise le port série.
  Serial.begin(9600);

  Serial.println("Starting the I2C interface.");
  Wire.begin(); // Démarre l'interface I2C.

  Serial.println("Constructing new HMC5883L");
  compass = HMC5883L(); // Construit une nouvelle boussole HMC5883L
    
  Serial.println("Setting scale to +/- 1.3 Ga");
  error = compass.SetScale(1.3); // Règle l'échelle de la boussole.
  if(error != 0) // Si il y a une erreur, l'afficher.
    Serial.println(compass.GetErrorText(error));
  
  Serial.println("Setting measurement mode to continous.");
  error = compass.SetMeasurementMode(Measurement_Continuous); // Réglez le mode de mesure Continu.
  if(error != 0) // Si il y a une erreur, l'afficher.
    Serial.println(compass.GetErrorText(error));
}

// Boucle principale du programme.
void loop()
{
  // Récupérer les valeurs de ligne de la boussole (pas à l'échelle)
  MagnetometerRaw raw = compass.ReadRawAxis();
  // Récupérée les valeurs mises à l'échelle de la boussole (à l'échelle de l'échelle configurée).
  MagnetometerScaled scaled = compass.ReadScaledAxis();
  
  // Valeurs de la boussole :
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (ou YAxis, ou ZAxis)

  // Calculer la position 
  float heading = atan2(raw.YAxis, raw.XAxis);
  
  // Une fois que nous avez notre position, nous devez ajouter notre angle de déclinaison, qui est l'erreur du champ magnétique dans notre région.
  // On peut la trouver ici: http://www.magnetic-declination.com/
  // A Enghien les bains : 0° 37' W, qui correspond à 0.8727 milliradians.
  // on convertit les milliradians en radians :
  float declinationAngle = 0.8727/1000.0;
  heading -= declinationAngle;
  
  // Corrige si le signe est inversé
  if(heading < 0)
    heading += 2*PI;
    
  if(heading > 2*PI)
    heading -= 2*PI;
   
  // Convertit radian en degré pour la lecture
  float headingDegrees = heading * 180/M_PI; 

  // Sortie des données via le port série.
  Output(raw, scaled, heading, headingDegrees);


}

  // Sortie des données via le port série.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
   Serial.print("Raw:\t");
   Serial.print(raw.XAxis);
   Serial.print("   ");   
   Serial.print(raw.YAxis);
   Serial.print("   ");   
   Serial.print(raw.ZAxis);
   Serial.print("   \tScaled:\t");
   
   Serial.print(scaled.XAxis);
   Serial.print("   ");   
   Serial.print(scaled.YAxis);
   Serial.print("   ");   
   Serial.print(scaled.ZAxis);

   Serial.print("   \tHeading:\t");
   Serial.print(heading);
   Serial.print(" Radians   \t");
   Serial.print(headingDegrees);
   Serial.println(" Degrees   \t");
}

code du serveur web :

// EtherShield webserver demo
#include "EtherShield.h"

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {
  0x54,0x55,0x58,0x10,0x00,0x25}; 
  
static uint8_t myip[4] = {
  192,168,1,30};

#define MYWWWPORT 80
#define BUFFER_SIZE 550
static uint8_t buf[BUFFER_SIZE+1];

// The ethernet shield
EtherShield es=EtherShield();

uint16_t http200ok(void)
{
  return(es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n")));
}

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
  uint16_t plen;
  plen=http200ok();
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<html><head><title>Projet PPE 204</title></head><body>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center><h1>Bienvenue sur notre site</h1>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr>
<h2><font color=\"blue\">-- METEO -- "));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
 Direction du vent"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
 Vitesse du vent"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
</font></h2>") );
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center><hr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<a href=\"http://www.lyc-monod-enghien.ac-versailles.fr/\">Lycée Gustave Monod</a>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</body></html>"));

  return(plen);
}


void setup(){

  // Initialise SPI interface
  es.ES_enc28j60SpiInit();

  // initialize enc28j60
  es.ES_enc28j60Init(mymac);

  // init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
}

void loop(){
  uint16_t plen, dat_p;

  while(1) {
    // read packet, handle ping and wait for a tcp packet:
    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));

    /* dat_p will be unequal to zero if there is a valid 
     * http get */
    if(dat_p==0){
      // no http request
      continue;
    }
    // tcp port 80 begin
    if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
      // head, post and other methods:
      dat_p=http200ok();
      dat_p=es.ES_fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>"));
      goto SENDTCP;
    }
    // just one web page in the "root directory" of the web server
    if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
      dat_p=print_webpage(buf);
      goto SENDTCP;
    }
    else{
      dat_p=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
      goto SENDTCP;
    }
SENDTCP:
    es.ES_www_server_reply(buf,dat_p); // send web page data
    // tcp port 80 end

  }

}

Merci

bonjour,

Je voudrais envoyer ces informations sur un site web grâce à mon shield ethernet.
J'ai un code me permettant de créer un serveur web mais je n'arrive pas à combiner les 2 codes (code de la girouette et du shield) pour avoir l'orientation du vent sur mon serveur.

faut savoir, soit tu envoies sur un server les données, soit tu héberge le server sur l'arduino.

Déja je veux faire marcher sa en local après j'hebergerais grâce à un dsn (dyndns ou no-ip)

tahsc:
Déja je veux faire marcher sa en local après j'hebergerais grâce à un dsn (dyndns ou no-ip)

CAD?
sur un server en local ou directement sur l'arduino en mode server?
local ou distant, ca reveint au même sauf les ip
page sur l'arduino en mode server, pas la même chose :wink:

DIrectement grâce à l'IP du shield que je connecterais à mon routeur.
En accédant à son IP, je pourrais voir ma page html avec les informations dessus.
Je ne vois pas trop ce que tu veux dire :stuck_out_tongue:

infobarquee:
bonjour,

Je voudrais envoyer ces informations sur un site web grâce à mon shield ethernet.
J'ai un code me permettant de créer un serveur web mais je n'arrive pas à combiner les 2 codes (code de la girouette et du shield) pour avoir l'orientation du vent sur mon serveur.

faut savoir, soit tu envoies sur un server les données, soit tu héberge le server sur l'arduino.

tu veux envoyer les données sur un site distant
OU
tu veux avoir la page html sur l'arduino

faut savoir exactement ce que tu veux :wink:
envoyer les données sur un site web distant (pc en local ou site a tréfouillis les coincs) = shield mode client
afficher les données sur une page html sur le shield ethernet arduino = shield en mode server

lol je veux envoyer les informations sur un site distant (à tréfouillis les coincs comme tu me l'à dit :P)
donc shield en mode client :slight_smile:

tahsc:
lol je veux envoyer les informations sur un site distant (à tréfouillis les coincs comme tu me l'à dit :P)
donc shield en mode client :slight_smile:

donc pourquoi tu avoir fais un code en mode server?
les données seront envoyées puis stockées dans quoi?
fichier, bdd?

ca serait pas pour un TP pour le bac?

En fait je me suis mal exprimé hier,
je veux héberger le serveur sur l'arduino, c'est à dire avoir l'arduino en mode server.
Je veux donc avoir la page HTML sur l'arduino.
Excuse moi j'était tellement fatigué que je comprenais même plus ce que j'écrivais lol

Voici mon code qui me permet de créer mon petit serveur sur l'arduino :

// EtherShield webserver demo
#include "EtherShield.h"
#include <HMC5883L.h>
#include <Wire.h>

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {
  0x54,0x55,0x58,0x10,0x00,0x25}; 
  
static uint8_t myip[4] = {
  192,168,1,30};

#define MYWWWPORT 80
#define BUFFER_SIZE 550

// déclare notre boussole comme une variable.
HMC5883L compass;

// Enregistre toute erreur provoquée par la boussole.
int error = 0;

static uint8_t buf[BUFFER_SIZE+1];

// The ethernet shield
EtherShield es=EtherShield();

uint16_t http200ok(void)
{
  return(es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n")));
}




void setup(){

 { // Initialise SPI interface
  es.ES_enc28j60SpiInit();

  // initialize enc28j60
  es.ES_enc28j60Init(mymac);

  // init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
}

{

   // Initialise le port série.
  Serial.begin(9600);

  Serial.println("Starting the I2C interface.");
  Wire.begin(); // Démarre l'interface I2C.

  Serial.println("Constructing new HMC5883L");
  compass = HMC5883L(); // Construit une nouvelle boussole HMC5883L
    
  Serial.println("Setting scale to +/- 1.3 Ga");
  error = compass.SetScale(1.3); // Règle l'échelle de la boussole.
  if(error != 0) // Si il y a une erreur, l'afficher.
    Serial.println(compass.GetErrorText(error));
  
  Serial.println("Setting measurement mode to continous.");
  error = compass.SetMeasurementMode(Measurement_Continuous); // Réglez le mode de mesure Continu.
  if(error != 0) // Si il y a une erreur, l'afficher.
    Serial.println(compass.GetErrorText(error));
}}
void loop(){
 { uint16_t plen, dat_p;

  while(1) {
    // read packet, handle ping and wait for a tcp packet:
    dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));

    /* dat_p will be unequal to zero if there is a valid 
     * http get */
    if(dat_p==0){
      // no http request
      continue;
    }
    // tcp port 80 begin
    if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
      // head, post and other methods:
      dat_p=http200ok();
      dat_p=es.ES_fill_tcp_data_p(buf,dat_p,PSTR("<h1>200 OK</h1>"));
      goto SENDTCP;
    }
    // just one web page in the "root directory" of the web server
    if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
      dat_p=print_webpage(buf);
      goto SENDTCP;
    }
    else{
      dat_p=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
      goto SENDTCP;
    }
SENDTCP:
    es.ES_www_server_reply(buf,dat_p); // send web page data
    // tcp port 80 end

  }

}

{
  // Récupérer les valeurs de ligne de la boussole (pas à l'échelle)
  MagnetometerRaw raw = compass.ReadRawAxis();
  // Récupérée les valeurs mises à l'échelle de la boussole (à l'échelle de l'échelle configurée).
  MagnetometerScaled scaled = compass.ReadScaledAxis();
  
  // Valeurs de la boussole :
  int MilliGauss_OnThe_XAxis = scaled.XAxis;// (ou YAxis, ou ZAxis)

  // Calculer la position 
  float heading = atan2(raw.YAxis, raw.XAxis);
  
  // Une fois que nous avez notre position, nous devez ajouter notre angle de déclinaison, qui est l'erreur du champ magnétique dans notre région.
  // On peut la trouver ici: http://www.magnetic-declination.com/
  // A Enghien les bains : 0° 37' W, qui correspond à 0.8727 milliradians.
  // on convertit les milliradians en radians :
  float declinationAngle = 0.8727/1000.0;
  heading -= declinationAngle;
  
  // Corrige si le signe est inversé
  if(heading < 0)
    heading += 2*PI;
    
  if(heading > 2*PI)
    heading -= 2*PI;
   
  // Convertit radian en degré pour la lecture
  float headingDegrees = heading * 180/M_PI; 

  // Sortie des données via le port série.
  Output(raw, scaled, heading, headingDegrees);


}
}

 // Sortie des données via le port série.
void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees)
{
   Serial.print("Raw:\t");
   Serial.print(raw.XAxis);
   Serial.print("   ");   
   Serial.print(raw.YAxis);
   Serial.print("   ");   
   Serial.print(raw.ZAxis);
   Serial.print("   \tScaled:\t");
   
   Serial.print(scaled.XAxis);
   Serial.print("   ");   
   Serial.print(scaled.YAxis);
   Serial.print("   ");   
   Serial.print(scaled.ZAxis);

   Serial.print("   \tHeading:\t");
   Serial.print(heading);
   Serial.print(" Radians   \t");
   Serial.print(headingDegrees);
   Serial.println(" Degrees   \t");
}

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
  uint16_t plen;
  plen=http200ok();
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<html><meta charset='UTF-8'><head><title>Projet PPE 2014</title></head><body>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
</font></h2>") );
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center><hr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<table width= '200' border= '1' >"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<tr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>raw</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>scaled</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>heading(rad)</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>heading(°)</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</tr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<tr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>&nbsp;</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>&nbsp;</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>&nbsp;</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>&nbsp;</td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</tr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</table>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<p>&nbsp;</p>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<p>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<a href=\"http://www.lyc-monod-enghien.ac-versailles.fr/\">Lycée Gustave Monod</a>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</body></html>"));

  return(plen);
}

et voici une capture de mon serveur.

Comme on le vois, j'ai bien mon tableau mais dans la deuxième colonne, je voudrais les valeurs de mes variables mais dès que je remplace les "&nbsp" par le nom d'une de mes variables en faisant

 plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<td>"));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(heading));
  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td>"));

j'ai une erreur qui est "heading was not declared in this scope" alors je l'ai déclaré juste au dessus pour avoir mes variables sur le port série.

Comment résoudre ce problème?
Et oui c'est pour le bac
Merci

En fait c'est bon pour la declaration des variables, j'ai déplacé mon code html au dessus des Serial.print (pour la sortie vers le port série).

Mais maintenant j'ai une autre erreur qui est "initializer fails to determine size of '__c'".

Je crois que c'est une erreur de mémoire à cause de mes PSTR mais je ne sais pas quoi mettre à la place.

  plen=es.ES_fill_tcp_data_p(buf,plen,PSTR(heading));

Qui peut m'aider?