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.