So I have most likly been looking at this too long myself and just missing something painfully obvious. So I will reach out to the community for help. Below you will see my code. I swear if I take the same NTP bit of the code out, and do serial prints like the example, it works great, but then I can't get it in the web form because it says the stuff isn't defined in that scope, however, if I put it in the section where it is in the example, it says "'sendNTPpacket' was not declared in this scope" so I don't what I'm missing and would be super happy if someone could help.
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Udp.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <Time.h>
Adafruit_BMP085 bmp = Adafruit_BMP085(10085);
void displaySensorDetails(void)
{
sensor_t sensor;
bmp.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print ("Sensor: "); Serial.println(sensor.name);
Serial.print ("Driver Ver: "); Serial.println(sensor.version);
Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" hPa");
Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" hPa");
Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" hPa");
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}
const int VAL_PROBE = 0;
const int MOISTURE_LEVEL = 250;
int LDR_Pin = A1;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 };
IPAddress ip(192,168,137,123);
unsigned int localPort = 8888;
IPAddress timeServer(132, 163, 4, 101);
const int NTP_PACKET_SIZE= 48;
byte packetBuffer [ NTP_PACKET_SIZE ];
EthernetUDP Udp;
EthernetServer server(80);
void setup(void)
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
Udp.begin(localPort);
Serial.println("Pressure Sensor Test"); Serial.println("");
/* Initialise the sensor */
if(!bmp.begin())
{
/* There was a problem detecting the BMP085 ... check your connections */
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!");
while(1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
}
void loop(void)
{
/* My NTP Crap */
sendNTPpacket(timeServer);
delay(1000);
if ( Udp.parsePacket() ) {
Udp.read(packetBuffer,NTP_PACKET_SIZE);
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
unsigned long secsSince1900 = highWord << 16 | lowWord;
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
}
unsigned long sendNTPpacket(IPAddress& address)
memset(packetBuffer, 0, NTP_PACKET_SIZE);
packetBuffer[0] = 0b11100011;
packetBuffer[1] = 0;
packetBuffer[2] = 6;
packetBuffer[3] = 0xEC;
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer,NTP_PACKET_SIZE);
Udp.endPacket();
/* End my NTP crap */
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
/*
client.println("<meta http-equiv=refresh content=3>");
*/
// read in the temperature
int moisture = analogRead(VAL_PROBE);
int LDRReading = analogRead(LDR_Pin);
sensors_event_t event;
bmp.getEvent(&event);
float temperature;
bmp.getTemperature(&temperature);
float tempfa;
int tempf = (temperature * 9.0 / 5.0 +32);
client.println("<table>");
client.println("<tr>");
client.print("<td>");
Client.print((epoch % 86400L) / 3600);
Client.print(':');
if ( ((epoch % 3600) / 60) < 10 ) {
// In the first 10 minutes of each hour, we'll want a leading '0'
Client.print('0');
}
Client.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
Client.print(':');
if ( (epoch % 60) < 10 ) {
// In the first 10 seconds of each minute, we'll want a leading '0'
Client.print('0');
}
Client.println(epoch %60); // print the second
client.print("</td");
client.print("<td>");
client.print("Pressure: ");
client.print("</td>");
client.print("<td>");
client.print(event.pressure);
client.print("</td><td>");
client.print(" hPa");
client.print("</td></tr>");
client.print("<tr>");
client.print("<td>");
client.print("Temperature: ");
client.print("</td><td>");
client.print(tempf);
client.print("</td><td>");
client.print(" degrees");
client.println("</td></tr>");
client.println("<tr><td>");
client.print("Moisture Level: ");
client.println("</td><td>");
client.print(moisture);
client.println("</td><td></td></tr>");
client.println("<tr><td>");
client.print("Light Level: ");
client.println("</td><td>");
client.print(LDRReading);
client.println("</td><td></td></tr>");
client.println("</table>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}
}