Hey Dan,
thanks for the code sample, not really what I was after, but I managed to work it out in the end, I have shared the code below in case it helps others, it seems to be working fine, it connects to a little board I built that sends a pulse to one of the I/O pins every time the light flashes on our solar panel generation meter, and then sends it as a hit via UDP to our Graphite server
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
int status = WL_IDLE_STATUS; // the Wifi radio's status
bool lastSensorStateOn = false;
WiFiUDP Udp;
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
}
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(1, OUTPUT); //LED
pinMode(8, INPUT); //Input for light reader
// attempt to connect to Wifi network:
while ( WiFi.status() != WL_CONNECTED) {
status = WiFi.begin();
Serial.print("Attempting a connect to WIFI: ");
Serial.println(status);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the data:
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
}
void loop() { digitalWrite(1,LOW); //Turn LED on
if (digitalRead(8) == HIGH)
{
if (!lastSensorStateOn)
{
lastSensorStateOn = true;
// turn on the LED
digitalWrite(1,HIGH); //Turn LED on
LogStat();
}
}
else
{
lastSensorStateOn = false;
}
delay(20);
}
void LogStat()
{
/* NetworkInterface niInterface = new NetworkInterface();
niInterface.Port = 8125;
niInterface.Ip = "10.0.50.93";
niInterface.SendMessage("SolarKWGenerated.count:1|c");
*/
IPAddress ip = IPAddress(10,0,50,93);
Udp.beginPacket(ip, 8125);
Udp.write("SolarKWGenerated.count:1|c");
Udp.endPacket();
Serial.println("Sent to Graphite 1");
}