Hi,
This is my equipment.
- Portenta H7 Version 2
- Portenta Mid Carrier
- Portenta Pro 4G module.
- PLC with modbus communication over Etherent.
Currently I have an issue that when the Etherent cable is unplugged or the IP is incorrect to the PLC the cellular connection of the 4G modem to the cloud is disconnected.
The mid carrier is connected to a PLC via Ethernet. The setup connects over Etherent to the PLC with Modbus TCP/IP. The data from this is send via cellular modem to the cloud and displayed on a dashboard.
If the cable is connected back in an/or the IP has been fixed. It start sending data again to the cloud. So it restores the data transmission via the modem after the Ethernet connections fixed.
To me it seems the H7 goes into a never ending loop when the Etherent connection is not operational. Probaly waiting for the Ethernet connection to be restored. This then is causing no other code to be exicuted. Including the cellular modem code.
This is used in remote areas where there is only cellular connection available to connect to the cloud.
Below is part of my code. My qeustions are the follwing;
1.) Can it be that the H7 goes into the never ending loop if the Etherent is not operation due to the cable not connected or the IP address of the server is incorrect?
2.) Can one add code or change code that keep the cellular connection to the cloud intact even if the ethenet connection is not operational? Basically prioritize the cell connection above the ethenet connection to the PLC?
any comments and suggestions are welcomed.
#include "thingProperties.h"
#include <SPI.h>
#include <PortentaEthernet.h>
#include <Ethernet.h>
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
#include "DHT.h"
#include "I2C_24LC1025.h"
I2C_24LC1025 myMem(0x50);
/************Modbus*************************/
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 100, 198);
EthernetClient ethClient;
ModbusTCPClient modbusTCPClient(ethClient);
IPAddress server(192, 168, 100, 9); // Plc address
/**************DHT22 Config************************/
#define DHTPIN D0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
Wire.begin();
delay(1000);
if(!myMem.begin()){
Serial.println("EEPROM not found");
} else {
Serial.println("EEPROM good to go");
}
Ethernet.begin(mac, ip);
modbusTCPClient.begin(server, 502);
dht.begin();
}
void loop() {
ArduinoCloud.update();
if (Ethernet.linkStatus() == LinkOFF) {
systemMessages = "Cable not connected or damaged";
} else {
if (!modbusTCPClient.connected()) {
systemMessages = "Attempting to reconnect Modbus...";
delay(1000);
Ethernet.begin(mac, ip);
delay(1000);
modbusTCPClient.begin(server, 502);
}
}
if(modbusTCPClient.connected()) {
doModbus();
systemMessages = "Modbus Connected";
}
doTime();
doDHT22();
doStatus();
balesPerHour();
balesPerDay();
loading();
eventLogging();
doscaling();
}