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