Ethernet connection

Hello community,

Hope your are doing well during this bad time.

I'm working on a project that use an arduino uno with an ethernet shield.

/1- Include for scada communication
#include <SPI.h>
#include <Ethernet.h>

//2- Include for main program
#include <CaV.h>
#include <Tempo.h>

//3- Constante definition

#define Cav_XM_Fwd 3
#define Cav_XM_Rev 4
#define Cav_XM_Stop 5
#define Cav_YL_01 6
#define Cav_YL_02 7

//4- Déclaration des variables globales
CaV Cav; 
int Etape;
String FirstLine="";

// L'adresse MAC du shield
byte mac[] = { 0x02, 0x0F, 0xB5, 0x0E, 0xA5, 0x7E };
// L'adresse IP que prendra le shield
IPAddress ip(192,168,1,65);

// Initialise notre serveur
// Ce dernier écoutera sur le port 80
EthernetServer serveur(80);


//5- Declaration des fonctions

void StateDiagram();  
void ReadInputFromScada();

//6- Setup
void setup() {
  ///6.1- HW configuration
  pinMode(Cav_YL_02, OUTPUT);
  pinMode(Cav_XM_Fwd, OUTPUT);
  pinMode(Cav_XM_Rev, OUTPUT);
  pinMode(Cav_XM_Stop, OUTPUT);
  digitalWrite(Cav_YL_02, LOW);
  digitalWrite(Cav_XM_Fwd, LOW);
  digitalWrite(Cav_XM_Rev, LOW);
  digitalWrite(Cav_XM_Stop, LOW);

  ///6.2- Network configuration
  
  //Variable initialisation
  Etape = 0;
  // On démarre la voie série pour déboguer
  Serial.begin(9600);

  char erreur = 0;
  // On démarre le shield Ethernet SANS adresse IP (donc donnée via DHCP)
  erreur = Ethernet.begin(mac);

  if (erreur == 0) {
    Serial.println("Parametrage avec ip fixe...");
    // si une erreur a eu lieu cela signifie que l'attribution DHCP
    // ne fonctionne pas. On initialise donc en forçant une IP
    Ethernet.begin(mac, ip);
  }
  
  Serial.println("Pret !");  
  Serial.print("Adresse arduino : ");
  Serial.println(Ethernet.localIP());
  
}

//7- Loop
void loop() {
  //Declaration des variables
  bool OpenHatch;
  bool CloseHatch;
  long TempoOpen;
  long TempoClose;
  /*----------------------------------------------*/
  ///            Read input                      ///
  /*----------------------------------------------*/
  ReadInputFromScada();  
  /*----------------------------------------------*/
  ///            Main program                    ///
  /*----------------------------------------------*/
  //StateDiagram();

    
  /*----------------------------------------------*/
  ///            Write output                    ///
  /*----------------------------------------------*/
  /*Serial.print("Main sequence step : ");
  Serial.print(Etape);
  Serial.print(" - State : ");
  Serial.print(Cav.state);
  Serial.print(" - Strategy : ");
  Serial.print(Cav.QCS);
  Serial.print(" - Etape : ");
  Serial.print(Cav.step);
  Serial.print(" - Moteur avant : ");
  Serial.print(Cav.CavXMFwd);
  Serial.print(" - Moteur Arrière : ");
  Serial.println(Cav.CavXMRev);*/
  /*
  digitalWrite(Cav_YL_02,Cav.CavYL02==1?HIGH:LOW);
  digitalWrite(Cav_XM_Fwd,Cav.CavXMFwd==1?HIGH:LOW);
  digitalWrite(Cav_XM_Rev,Cav.CavXMRev==1?HIGH:LOW);*/


  delay(1000);
}

I don't put all class code because it's too long and it's not linked to the communication.

I push the code in the arduino, I've got some error but, it's arrived at the end (here are errors):

/home/bap/Arduino/HomeTomation/01- Cave à vin/CaveAVin_Rev01/CaveAVin_Rev01.ino:145:62: warning: character constant too long for its type
   ParametersAndValue = FirstLine.substring(FirstLine.indexOf('httpds?')+1,FirstLine.indexOf(" HTTP/1.1"));
                                                              ^~~~~~~~~
/home/bap/Arduino/HomeTomation/01- Cave à vin/CaveAVin_Rev01/CaveAVin_Rev01.ino: In function 'void GET(EthernetClient)':
/home/bap/Arduino/HomeTomation/01- Cave à vin/CaveAVin_Rev01/CaveAVin_Rev01.ino:145:71: warning: overflow in implicit constant conversion [-Woverflow]
   ParametersAndValue = FirstLine.substring(FirstLine.indexOf('httpds?')+1,FirstLine.indexOf(" HTTP/1.1"));
                                                                       ^
In file included from /home/bap/Applications/Arduino/arduino-1.8.11/libraries/Ethernet/src/Dns.cpp:8:0:
/home/bap/Applications/Arduino/arduino-1.8.11/libraries/Ethernet/src/Dns.cpp: In member function 'uint16_t DNSClient::BuildRequest(const char*)':
/home/bap/Applications/Arduino/arduino-1.8.11/libraries/Ethernet/src/utility/w5100.h:457:25: warning: result of '(256 << 8)' requires 18 bits to represent, but 'int' only has 16 bits [-Wshift-overflow=]
 #define htons(x) ( (((x)<<8)&0xFF00) | (((x)>>8)&0xFF) )
                      ~~~^~~
/home/bap/Applications/Arduino/arduino-1.8.11/libraries/Ethernet/src/Dns.cpp:164:18: note: in expansion of macro 'htons'
  twoByteBuffer = htons(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
                  ^~~~~

I don't think it can lead to an error.
If I let the arduino on the USB (for the power supply), it's running well.

When I put the arduino on a 12VDC power supply, I can see the arduino on the network but after a couple of minutes, leds on the ethernet shield power off. It only remains the one with PWR indicated.

I've change the arduino uno and the ethernet shield without success.

Somebody has an idea ?

Thanks a lot,

PP

Next post, please use the Code tags button, </> on the menu, for code and error messages.
Thanks
Moderator.

Hello and welcome

What Ethernet shield model are you using?
Are you feeding 12VDC directly into the Arduino?

It is worth reading the guidelines for using the Forum and using code blocks rther than quote for your code listing (use the </> to insert the code - that way we can see all the code rather than the smiley faces!

there are some warnings from the libraries. Leave them as they are.

The warning you caused, is not in the snippet you were posting.
Remember: it's not worth the time to see uncomplete code. Either post full code or strip down your sketch to a version still showing the warning.

String.IndexOf() only allows for a single character to be searched for, if you wish to find another string you should use substring()