[SOLVED] Portenta Machine Control (PMC) WiFi Access Point using Arduino PLC IDE

I recently got myself a PMC to develop a small industrial application. I followed the setup instructions and the board works as intended. I managed to test a few applications written in LD and encountered no problems.

I am now trying to add WiFi to my project in order to communicate with several nearby wireless sensors. The PMC should be configured as a WiFi access point running a local webserver. The wireless sensors sensors would send information to the server. The information from the sensors is used by the PMC in the LD program for different functions.

I have found examples of using the Portenta H7 as a WiFi access point running a webserver here and example of passing variables between the sketch and PLC language layer for an Arduino OPTA here. So from my understanding it should be possible to implement this on the PMC with the PLC IDE.

For now I have attempted just to configure the PMC as an access point with no success.
In the sketch tab of the PLC IDE I wrote the following code:

#include <WiFi.h>

char ssid[] = "PMC_AP"; 
char pass[] = "password"; 
int keyIndex = 0; 
int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
  Serial.begin(9600);
  WiFi.beginAP(ssid,pass);
  Serial.println("Setup");
}

void loop() {
Serial.println("Loop"); // to check if looping
delay(1000);
}

I have also defined the WiFi library in the appropriate table (Version 1.2.7).

The code compiles without errors and I am also able to download it on the PMC. The problem is that it does not appear to be working. There is no new AP nearby with the programmed name and there is nothing appearing on the serial monitor.

Another problem is that once uploaded, I cannot connect to the PMC via the PLC IDE. The IDE just freezes when attempting to connect and has to be closed via Task Manager. When reinitialising the board as in the setup instructions, I am able to connect again.

I have tried small other code snippets using different libraries (not WiFi specific) and the results were similar.

Is there something I am missing? Or is it just impossible to do? I was not able to find much information on this topic, and the official documentation is also not helping much.

Some help would be greatly appreciated.

Managed to solve the issue. Had to update the WiFi firmware as instructed here. I am attaching the example code bellow for anybody who is interested. The code also passes variables between the sketch layer and the LD program.

#include <WiFi.h>

char ssid[] = "PMC";    // your network SSID (name)
char pass[] = "123456789";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;             // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

bool a = false;
int ct=0;

void setup() {
Serial.begin(9600);
delay(1500);
while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
Serial.println("Access Point Web Server");
Serial.print("Creating access point named: ");
Serial.println(ssid);

  //Create the Access point
  status = WiFi.beginAP(ssid,pass);
  if(status != WL_AP_LISTENING){
    Serial.println("Creating access point failed");
    // don't continue
    while (true);
  }

  // wait 10 seconds for connection:
  delay(10000);

  // start the web server on port 80
  server.begin();

  // you're connected now, so print out the status
  printWiFiStatus();
}

void loop() {
    ct++;
    Serial.println(ct);
    a=true;
    PLCIn.a_sh=a;
    delay(1000);
    a=false;
    PLCIn.a_sh=a;
    delay(2000);
    if (status != WiFi.status()) {
    // it has changed update the variable
    status = WiFi.status();

    if (status == WL_AP_CONNECTED) {
      // a device has connected to the AP
      Serial.println("Device connected to AP");
    } else {
      // a device has disconnected from the AP, and we are back in listening mode
      Serial.println("Device disconnected from AP");
    }
  }
}

void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your Wi-Fi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}

After uploading you have to open the serial com in order for the setup to complete. The board also connects to the PLC IDE without trouble. Apparently it got stuck when opening the serial com and that is why the IDE would freeze.