Partage
  • Partager sur Facebook
  • Partager sur Twitter

Ethernet shield + virtualWire

Sujet résolu
    11 mars 2014 à 10:54:48

    Bonjour,

    Voici mon problème : J’ai une arduino uno avec un ethenet shield et un émetteur 433 Mhz de brancher dessus, le pin data de l’émetteur est relier au pin 6 de mon arduino. J’ai l’impression que certaines commandes de la librairie VirtualWire font buger mon code, je m’explique, par exemple la commande « vw_setup() » fait buger le code mais quand je la met dans un commentaire le code fonctionne, de même pour des autres commandes entre la ligne 149 et 162.

    Voici le code :

    Thibaut.Bonjour,

    Voici mon problème : J’ai une arduino uno avec un ethenet shield et un émetteur 433 Mhz de brancher dessus, le pin data de l’émetteur est relier au pin 6 de mon arduino. J’ai l’impression que certaines commandes de la librairie VirtualWire font buger mon code, je m’explique, par exemple la commande « vw_setup() » fait buger le code mais quand je la met dans un commentaire le code fonctionne, de même pour des autres commandes entre la ligne 165 et 178.

    Voici le code :

    #include <SPI.h>
    #include <Ethernet.h>
    #include <string.h>
    #include <VirtualWire.h>
    
    // MAC address can be anything that is unique within your network.
    // IP is the address the Arduino Ethernet Card would respond to.  It needs to be an unused address within your network.
    byte mac[] = {  
      0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
    IPAddress ip(192,168,1,28); // This is typically 10.0.0.x
    
    EthernetServer server(80); // Port 80 is http.EthernetClient client = server.available();
    
    //-- Commands and parameters (sent by browser) --
    char cmd[15];    // Nothing magical about 15, increase these if you need longer commands/parameters
    char param1[15];
    char param2[15];
    
    //-- Sample Ports ---
    void SetupSamplePorts()
    {
      // To illustrate how to use this, I have an LED and a Potentiometer.
      // The 10K potentiometer left lead is connected to GND, right lead to +5V, and middle lead to Analog 0.
      // The LED cathode is on digital pin 7 and anode is on pin 8.
      pinMode(7,OUTPUT); digitalWrite(7,LOW);  // I use this pin as GND for the LED.
      pinMode(8,OUTPUT); // Sample output, unable to use built-in LED at pin 13 because Ethernet Shield uses pins 10,11,12,13.
      pinMode(9,OUTPUT);
    }
    
    void setup()
    {
      Ethernet.begin(mac, ip);
      server.begin();
    
      Serial.begin(57600);
      SetupSamplePorts();
      
      //vw_setup(100);
      vw_set_tx_pin(6);
      
    }
    
    void send (char *message)
    {
      vw_send((uint8_t *)message, strlen(message));
      vw_wait_tx();
    }
    
    #define bufferMax 30
    int bufferSize;
    char buffer[bufferMax];
    
    void loop()
    {
      EthernetClient client = server.available();
      if (client)
      {
        WaitForRequest(client);
        ParseReceivedRequest();
        PerformRequestedCommands();
        
        client.stop();
      }
    }
    
    void WaitForRequest(EthernetClient client) // Sets buffer[] and bufferSize
    {
      bufferSize = 0;
     
      while (client.connected()) {
        if (client.available()) {
          char c = client.read();
          if (c == '\n')
            break;
          else
            if (bufferSize < bufferMax)
              buffer[bufferSize++] = c;
            else
              break;
        }
      }
      
      PrintNumber("bufferSize", bufferSize);
    }
    
    void ParseReceivedRequest()
    {
      Serial.println("in ParseReceivedRequest");
      Serial.println(buffer);
      
      //Received buffer contains "GET /cmd/param1/param2 HTTP/1.1".  Break it up.
      char* slash1;
      char* slash2;
      char* slash3;
      char* space2;
      
      slash1 = strstr(buffer, "/") + 1; // Look for first slash
      slash2 = strstr(slash1, "/") + 1; // second slash
      slash3 = strstr(slash2, "/") + 1; // third slash
      space2 = strstr(slash2, " ") + 1; // space after second slash (in case there is no third slash)
      if (slash3 > space2) slash3=slash2;
    
      PrintString("slash1",slash1);
      PrintString("slash2",slash2);
      PrintString("slash3",slash3);
      PrintString("space2",space2);
      
      // strncpy does not automatically add terminating zero, but strncat does! So start with blank string and concatenate.
      cmd[0] = 0;
      param1[0] = 0;
      param2[0] = 0;
      strncat(cmd, slash1, slash2-slash1-1);
      strncat(param1, slash2, slash3-slash2-1);
      strncat(param2, slash3, space2-slash3-1);
      
      PrintString("cmd",cmd);
      PrintString("param1",param1);
      PrintString("param2",param2);
    }
    
    void PerformRequestedCommands()
    {
      if ( strcmp(cmd,"digitalWrite") == 0 ) RemoteDigitalWrite();
      if ( strcmp(cmd,"analogRead") == 0 ) RemoteAnalogRead();
    }
    
    void RemoteDigitalWrite()
    {
      /*int ledPin = param1[0] - '0'; // Param1 should be one digit port
      int ledState = param2[0] - '0'; // Param2 should be either 1 or 0
      digitalWrite(ledPin, ledState);
     
      //-- Send response back to browser --
      server.print("D");
      server.print(ledPin, DEC);
      server.print(" is ");
      server.print( (ledState==1) ? "ON" : "off" );
    
      //-- Send debug message to serial port --
      Serial.println("RemoteDigitalWrite");
      PrintNumber("ledPin", ledPin);
      PrintNumber("ledState", ledState);*/
      server.print("coucou");
      
      
      //Cette partie de test fait buger aussi
      
      
      /*if(param1[0] == '1'){
        if(param2[0] == '1'){
          send("hello1");
          delay(1000);
        }else{
          send("hello0");
          delay(1000);
        }
      }else{
        send("hello1");
        delay(1000);
        send("hello0");
        delay(1000);
      }*/
      
      //Fin de la partie de test
    }
    
    void RemoteAnalogRead()
    {
      // If desired, use more server.print() to send http header instead of just sending the analog value.
      int analogPin = param1[0] - '0'; // Param1 should be one digit analog port
      int analogValue = analogRead(analogPin);
      
      //-- Send response back to browser --
      server.print("A");
      server.print(analogPin, DEC);
      server.print(" is ");
      server.print(analogValue,DEC);
      
      //-- Send debug message to serial port --
      Serial.println("RemoteAnalogRead");
      PrintNumber("analogPin", analogPin);
      PrintNumber("analogValue", analogValue);
    }
    
    void PrintString(char* label, char* str)
    {
      Serial.print(label);
      Serial.print("=");
      Serial.println(str);
    }
    
    void PrintNumber(char* label, int number)
    {
      Serial.print(label);
      Serial.print("=");
      Serial.println(number, DEC);
    }

    Thibaut.

    -
    Edité par luxe38 11 mars 2014 à 10:57:57

    • Partager sur Facebook
    • Partager sur Twitter
      11 mars 2014 à 18:56:40

      Ca sent le conflit de timer tout ca... du coup à moins de bricoler la librairie à la main il y a pas des milliers de solutions :s

      • Partager sur Facebook
      • Partager sur Twitter

      Retrouvez moi sur mon blog et ma chaine Youtube !

        13 mars 2014 à 13:54:15

        Merci,

        C’est bon j’ai poussé un peu plus mes recherche et j’ai résolue le problème. J’ai mis en « vw_setup() et vw_set_tx_pin » en premier dans le setup(), avant « Ethernet.begin() » et ça fonctionne. C’est un problème de priorité je pense.

        Thibaut.

        • Partager sur Facebook
        • Partager sur Twitter

        Ethernet shield + virtualWire

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown