Opening web page on a PC

Hello, I've searched a lot for an answer to this but no luck, so here I am. I can connect my Arduino rev2 wifi to a PC ( running EventGhost ) and I can direct it to access a web page, but rather than the Arduino opening the page, I need it to open the page on the web server ( the same PC, web server provided by event ghost. ) Here is the code:


#include <EtherEvent.h>
#include <WiFiNINA.h>
#include <WiFi.h>
#include <SPI.h>
#include "arduino_secrets.h"
#include <hd44780.h>
#include <Wire.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header

WiFiClient client;

int count=0;
int maxcount=1;
int sensorPin0 = A0;  //sensor pins
int sensorPin1 = A1;
int sensorValue0;
int sensorValue1;
int limit = 380;
int port = 8080;

const char pcbeast[] = "http://192.168.0.113/?shutdown";


hd44780_I2Cexp lcd;

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

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.println("BSSID: ");
  //    lcd.print("BSSID: ");
  //    lcd.print('/n');
  //    printMacAddress(bssid);
  //print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.println("signal strength (RSSI): ");
  Serial.println(rssi);
  

  //print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.println("Encryption Type: ");
  Serial.println(encryption, HEX);
  }

  void printWiFiData()
 {
  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.println("IP address : ");
  Serial.println(ip);
  lcd.setCursor(0, 0);
  lcd.print("IP address : ");
  lcd.setCursor(0, 1);
  lcd.print(ip);
  delay(3000);
  lcd.clear();
  
  Serial.println("Subnet mask: ");
  Serial.println((IPAddress)WiFi.subnetMask());
  
  Serial.println("Gateway IP : ");
  Serial.println((IPAddress)WiFi.gatewayIP());
  
  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.println("MAC address: ");
 } 

void setup()
{
  lcd.init();                      // initialize the lcd
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  lcd.backlight();
  Serial.begin(9600);
  while (!Serial)
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);


  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE)
  {
    Serial.println("Communication with WiFi failed!");
    lcd.setCursor(0, 0);
    lcd.print("Communication with");
    lcd.setCursor(0, 1);
    lcd.print("WiFi failed!");
    delay (1000);
    lcd.clear();
    // don't continue
    while (true);
  }

  else Serial.println("\nStarting connection...");
  {
    // if you get a connection, report back via serial:
    (client.connect(pcbeast, 80)); 
     Serial.println("connected");
    // Make a HTTP request:
     client.println("GET /search?q=arduino HTTP/1.0");
     client.println();
  } 
   
 
  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION)
  {
    Serial.println("Please upgrade the firmware");
    lcd.setCursor (0, 0);
    lcd.print("Please upgrade");
    lcd.setCursor (0, 1);
    lcd.print("the firmware");
    delay (2000);
    lcd.clear();
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED)
  {
    Serial.println("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    lcd.setCursor (0, 0);
    lcd.print("Attempting to ");
    lcd.setCursor (0, 1);
    lcd.print("connect to SSID: ");
    delay (1000);
    lcd.clear();
    delay (1000);
    lcd.setCursor (0, 0);
    lcd.print(ssid);
    // wait 5 seconds for connection:
    delay(5000);
    lcd.clear();
  
    // you're connected now, so print out the data:
   Serial.println("You're connected to the network");
   lcd.setCursor (0, 0);
   lcd.print("You're connected to ");
   lcd.setCursor (0, 1);
   lcd.print("the network");
   printCurrentNet();
   printWiFiData();
   delay(1000);
   lcd.clear();
   delay (1000);
 }  
}   

void loop()
{
  if (sensorValue0 < limit || sensorValue1 < limit)
  {
   digitalWrite(13, HIGH);
   digitalWrite(12, HIGH);
   
   client.connect(pcbeast, 8080);
   Serial.println("SHUTDOWN");
   lcd.setCursor (0, 1);
   lcd.print("SHUTDOWN");
   delay(2000);
   lcd.clear();
   delay (2000);
  }
  
  else
  {
   digitalWrite(13, LOW);
   digitalWrite(12, LOW);
   delay (1000);
  }
  
  pingResult = WiFi.ping(hostName);
  IPAddress ip = WiFi.localIP();
  if (pingResult >= 0)
  {
   Serial.println(pingResult);
   Serial.println(" ms");
   lcd.setCursor (0, 0);
   lcd.print("SUCCESS! RTT = ");
   lcd.print(pingResult);
   lcd.print(" ms");
   lcd.setCursor(0, 1);
   lcd.print("IP address : ");
   lcd.setCursor(0, 2);
   lcd.print(ip);
   delay(2000);
   lcd.clear();
   delay (2000);
        
   sensorValue0 = analogRead(sensorPin0);
   sensorValue1 = analogRead(sensorPin1);
   Serial.println("Analog Value : ");
   Serial.println(sensorValue0);
   Serial.println(sensorValue1);
   lcd.setCursor(0, 0);
   lcd.print("Analog Value0 : ");
   lcd.setCursor (0, 1);
   lcd.print(sensorValue0);
   delay (2000);
   lcd.clear();
   delay (2000);
   lcd.setCursor(0, 0);
   lcd.print("Analog Value1 : ");
   lcd.setCursor (0, 1);
   lcd.print(sensorValue1);
   delay (2000);
  
   lcd.clear();
   delay (2000);

  }
  else
  {
   Serial.println("FAILED! Error code: ");
   Serial.println(pingResult);
   lcd.setCursor(0, 0);
   lcd.print("FAILED! ");
   lcd.setCursor(0, 1);
   lcd.print("Error code: ");
   lcd.print(pingResult);
   delay(3000);
   lcd.clear();
   delay(1000);
  }
}

There may be some redundancy in the headers wrt networking but this is still a learning process for me. Any feedback appreciated.

This statement, issues by the Arduino, makes a request to the web server running on your PC:

If you want EventGhost to react to it, then I imagine that you will have to configure EventGhost and that there is little more that you can do on the Arduino.

The event seems to be configured properly, as it works when I test it on the machine that's running event ghost. The thing is I have a macro that I want to trigger ( shutdown ), but I don't know what to send from the Arduino to do that. What I have there so far isn't doing it.

Can you configure EventGhost to listen for activity on a particular network port ?
You could then contact that network port from the Arduino.
For a quick test, you could change this statement in your code:

(client.connect(pcbeast, 80)); // port 80 for HTTP

Cleaner would be to use an arduino telnet client.
You have to consider any firewalls between the communicating devices.

I think you are right about making the PC poll the Arduino for the data it needs. I set up the Arduino as a web server and my PC can communicate with it. Now I just have to get event ghost to read the appropriate variables and act on them. I've noticed EG wants Python commands to work with. I know more about C# than Python, but Using TCP Event to retrieve the data, I can't find any relevant command that the web server will accept.

I was actually suggesting that EventGhost could listen on a specific network port on the PC for any TCP activity and that would trigger the shutdown (or any other action you require). The Arduino could send to that network port as required. However, I don't know EventGhost so I can't say what is possible, although I have in the past, used netcat for sending and receiving arbitrary data to selected TCP/UDP ports which may be similar. However, I did find this by a quick google search : GitHub - per1234/TCPEvents: EventGhost plugin for sending and receiving events and data over a network. which appears to provide a TCP interface to EventGhost and the author @pert is, incidentally, an member of this forum.

Cool yeah, I am actually using TCPEvents, it's just that as with all plugins it wants Python code to tell the Arduino what to do, or look for or what have you. Event Ghost has a lot of available actions but not much info on how to trigger them. I've also had telnet working between the 2 but I don't know how to make that able to issue CMDs on the PC. I'm kind of stuck and running out of google results I haven't already seen.

Windows Command Line - EventGhost

Then, just open your browser via a .bat file:

Depending on your browser, you can open, set window size, pass URL, go into incognito, etc.

I would do that, or open a cmd window to enter a shutdown command or various other possibilities, but what I'm hung up on is getting my PC to listen to my Arduino. It listens in a web interface or in telnet, the communication is no problem, it's what to send to the PC to actually have it act that I'm stuck on.