Hello there,
I'm trying to get some variables value visible on a web page, using the OPTA like a WebServer.
First of all, i've tried with the Example tab using Arduino IDE, the " Ethernet WebServer" Example work very well...
But when I try to do the same with Arduino PLC the scketch compile, but seems that the WebServer never go up.
I cand get a ping response from the OPTA, but no web page are shown...
Does someaone be able to do that with Arduino PLC?
Does someone could post an example sketch?
3 Likes
After many thentative, still not able to get the WebServer wornking on OPTA device.
I've also update the mbed core to 4.2.0, but still not working.
// shared variables can be accessed with PLCIn.varname and PLCOut.varname
// Enable usage of EtherClass, to set static IP address and other
#include <PortentaEthernet.h>
arduino::EthernetClass eth(&m_netInterface);
EthernetServer server(80); //server port
String readString;
void setup()
{
Serial.begin(9600);
// Configure static IP address
IPAddress ip(192, 168, 188, 253);
IPAddress dns(8, 8, 8, 8);
IPAddress gateway(192, 168, 188, 1);
IPAddress subnet(255, 255, 255, 0);
// If cable is not connected this will block the start of PLC with about 60s of timeout!
eth.begin(ip, dns, gateway, subnet);
server.begin();
}
void loop()
{
EthernetClient client = server.available();
if (client) {
Serial.println("client");
while (client.connected()) {
Serial.println("connected");
if (client.available()) {
Serial.println("available");
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<BODY>");
client.println("<H1>Test</H1>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
//clearing string for next read
readString="";
}
}
}
}
}
On the serial console, i get some "connected" and then...nothing. It stuck.
1 Like
Has anyone got this to work?
I think it has to do with PortentaEthernet.h
other Arduino examples use the Ethernet.h include, which doesn't exist in the PLC sketch.
I was trying to follow the finder example: Web Server on the Finder Opta (findernet.com)
but they don't have the includes and the zip download of the example goes to a page not found
It would be appreciated if someone could share a working example of hosting a webpage on the OPTA device.
Thanks
I have found the zip file for the demo, have not yet opened it to confirm it works but I am having the same problem as you so hopefully this will help. The zip file is in the assets folder
https://github.com/dndg/FinderOptaWebServerTutorial
Just uploaded to my Opta and it seems to work ok. Note that I had to change the static IP address at three different locations in the sketch for it to work properly. (Line 21, 248, and 264)