Skip to content

Commit

Permalink
Merge pull request #29 from arduino-libraries/fix-no-wait-startup
Browse files Browse the repository at this point in the history
Fix: do no wait for a serial connection on startup.
  • Loading branch information
aentinger authored Oct 28, 2024
2 parents 70a243a + 6713ec6 commit af66697
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions examples/opta_opcua_server/opta_opcua_server.ino
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ static PinStatus arduino_opta_digital_read(pin_size_t const pin)
void setup()
{
Serial.begin(115200);
//auto const start = millis();
//for (; !Serial && (millis() - start) < 1000; ) { }
while (!Serial) { }
auto const start = millis();
for (; !Serial && (millis() - start) < 1000; ) { }

#if USE_MODBUS_SENSOR_MD02
RS485.setDelays(MODBUS_PRE_DELAY_BR, MODBUS_POST_DELAY_BR);
Expand Down Expand Up @@ -515,6 +514,15 @@ void loop()
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(500);

/* Periodically print OPC UA server IP and port. */
static auto prev_ip_print = millis();
auto const now = millis();
if ((now - prev_ip_print) > 5000)
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Arduino Opta IP: %s", Ethernet.localIP().toString().c_str());
prev_ip_print = now;
}

#if USE_MODBUS_SENSOR_MD02
if (!ModbusRTUClient.requestFrom(MODBUS_DEVICE_ID, INPUT_REGISTERS, MODBUS_DEVICE_TEMPERATURE_REGISTER, 1)) {
Serial.print("failed to read temperature register! ");
Expand Down

0 comments on commit af66697

Please sign in to comment.