Le forum a migré vers l'adresse suivante:

Forum

Masquer ce message

Simple-Duino Forum Index



Ethernet shield -


 
Post new topic   Reply to topic    Simple-Duino Forum Index -> Arduino & Électronique -> Questions
Previous topic :: Next topic  
Author Message
superdz
Débutant

Offline

Joined: 06 Jul 2014
Posts: 1
Masculin
Niveau d'éléctronique: Intermédiaire

PostPosted: Sun 6 Jul - 12:02 (2014)    Post subject: Ethernet shield - Reply with quote

PublicitéSupprimer les publicités ?
salut,

c'est mon premier post chez vous Surprised .
je bitouille arduino depuis quelque temps mais c'est la premiere fois que j'utilise un ethernet shield.

j'ai ecris un code pour recupérer des infos depuis une page web. C'est indice boursier, je dois donc vérifier régulierement s'il a eu une variationde cette derniere.

voici mon script
mais je ne le trouve pas classe Embarassed ... en effet je dois déconnecter puis reconnecter ma connection pour éviter la deconnection et obtenir une valeur...
merci

 
Code:
 [code]#include <SD.h>

#include <TextFinder.h>

#include <SPI.h>
#include <Ethernet.h>

File dataIndice;
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128);  // numeric IP for Google (no DNS)
char server[] = "bourse.capital.fr";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,0,177);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
TextFinder  finder( client );
unsigned int nbreConnection = 0;
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization SD failed!");
    return;
  }
  Serial.println("initialization SD done.");

}

void loop()
{   
  connection();
  if (
  finder.find("CoursVar"))
  {

    float valeur = finder.getFloat(',');
    //On affiche cette valeur à des fins de débuggage
    Serial.print("Valeur:  ");
    Serial.println(valeur/100);
    dataIndice = SD.open("Indice.txt", FILE_WRITE);
    if (dataIndice) {
      Serial.print("Writing to SD...");
      dataIndice.println(valeur/100);
      // close the file:
      dataIndice.close();
      Serial.println("done.");

    }
  };

  nbreConnection ++; 
  Serial.print("connection ");
  Serial.print(nbreConnection);
  Serial.println("terminé ");
  delay(1000);
}
void connection(){
      Serial.println("disconnecting.");
    client.stop();

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:


  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /cotation/nyse/cours-goldman-sachs-group-us38141g1040-266507 HTTP/1.1");
    client.println("Host: bourse.capital.fr");
    client.println("Connection: close");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:

    Serial.println("connection failed");
  }
}
[/code]

____________________________
Bricolage low and high tech
http://leresteux.net
Back to top
Contenu Sponsorisé






PostPosted: Today at 11:53 (2019)    Post subject: Ethernet shield -

Back to top
Display posts from previous:   
Post new topic   Reply to topic    Simple-Duino Forum Index -> Arduino & Électronique -> Questions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  

Index | Xooit.com free forum | Free support forum | Free forums directory | Report a violation | Conditions générales d'utilisation
Powered by phpBB
Propulsé par Simple-Duino