Some cosmetics
This commit is contained in:
parent
3f0796e617
commit
d88d174658
@ -1,24 +1,23 @@
|
|||||||
#include <SD.h>
|
#include <SD.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "BMP085.h"
|
#include "BMP085.h"
|
||||||
|
#include "Chronodot.h"
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#include "TSL2561.h"
|
#include "TSL2561.h"
|
||||||
#include "Chronodot.h"
|
|
||||||
|
|
||||||
#define TIMING 1000 // milliseconds
|
#define TIMING 1000 // milliseconds
|
||||||
#define DHTPIN 2
|
#define DHTPIN 2
|
||||||
#define DHTTYPE DHT22
|
#define DHTTYPE DHT22
|
||||||
#define SDPIN 4
|
#define SDPIN 4
|
||||||
|
|
||||||
BMP085 bmp;
|
BMP085 bmp;
|
||||||
DHT dht(DHTPIN, DHTTYPE);
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
TSL2561 tsl(TSL2561_ADDR_FLOAT);
|
TSL2561 tsl(TSL2561_ADDR_FLOAT);
|
||||||
Chronodot chronodot;
|
Chronodot chronodot;
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(5, OUTPUT);
|
|
||||||
|
|
||||||
//----- SD Card
|
//----- SD Card
|
||||||
Serial.println("INIT SD Card");
|
Serial.println("INIT SD Card");
|
||||||
@ -33,9 +32,9 @@ void setup() {
|
|||||||
Serial.println("INIT Sensors");
|
Serial.println("INIT Sensors");
|
||||||
|
|
||||||
bmp.begin();
|
bmp.begin();
|
||||||
|
chronodot.begin();
|
||||||
dht.begin();
|
dht.begin();
|
||||||
tsl.begin();
|
tsl.begin();
|
||||||
chronodot.begin();
|
|
||||||
|
|
||||||
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
|
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
|
||||||
//tsl.setGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
|
//tsl.setGain(TSL2561_GAIN_0X); // set no gain (for bright situtations)
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include "WebServer.h"
|
|
||||||
#include "BMP085.h"
|
#include "BMP085.h"
|
||||||
|
#include "Chronodot.h"
|
||||||
#include "DHT.h"
|
#include "DHT.h"
|
||||||
#include "TSL2561.h"
|
#include "TSL2561.h"
|
||||||
#include "Chronodot.h"
|
#include "WebServer.h"
|
||||||
|
|
||||||
#define TIMEZONE 7200 // 2 hours
|
#define TIMEZONE 7200 // 2 hours
|
||||||
#define DHTPIN 2
|
#define DHTPIN 2
|
||||||
#define DHTTYPE DHT22
|
#define DHTTYPE DHT22
|
||||||
#define PREFIX ""
|
#define PREFIX ""
|
||||||
#define NTP_PACKET_SIZE 48
|
#define NTP_PACKET_SIZE 48
|
||||||
|
|
||||||
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||||
@ -34,9 +34,9 @@ inline Print &operator <<(Print &obj, T arg)
|
|||||||
{ obj.print(arg); return obj; }
|
{ obj.print(arg); return obj; }
|
||||||
|
|
||||||
BMP085 bmp;
|
BMP085 bmp;
|
||||||
|
Chronodot chronodot;
|
||||||
DHT dht(DHTPIN, DHTTYPE);
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
TSL2561 tsl(TSL2561_ADDR_FLOAT);
|
TSL2561 tsl(TSL2561_ADDR_FLOAT);
|
||||||
Chronodot chronodot;
|
|
||||||
WebServer webserver(PREFIX, 80);
|
WebServer webserver(PREFIX, 80);
|
||||||
|
|
||||||
byte packetBuffer[ NTP_PACKET_SIZE];
|
byte packetBuffer[ NTP_PACKET_SIZE];
|
||||||
@ -52,8 +52,6 @@ void sensorsJsonCmd(WebServer &server, WebServer::ConnectionType type, char *url
|
|||||||
int32_t pressure = bmp.readPressure();
|
int32_t pressure = bmp.readPressure();
|
||||||
float altitude = bmp.readAltitude();
|
float altitude = bmp.readAltitude();
|
||||||
|
|
||||||
float humidity = dht.readHumidity();
|
|
||||||
|
|
||||||
uint32_t lum = tsl.getFullLuminosity();
|
uint32_t lum = tsl.getFullLuminosity();
|
||||||
uint16_t lightIr = lum >> 16;
|
uint16_t lightIr = lum >> 16;
|
||||||
uint16_t lightFull = lum & 0xFFFF;
|
uint16_t lightFull = lum & 0xFFFF;
|
||||||
@ -72,55 +70,54 @@ void sensorsJsonCmd(WebServer &server, WebServer::ConnectionType type, char *url
|
|||||||
<< "] }";
|
<< "] }";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Taken from http://arduino.cc/en/Tutorial/UdpNtpClient .
|
||||||
void sendNTPpacket() {
|
void sendNTPpacket() {
|
||||||
// set all bytes in the buffer to 0
|
// set all bytes in the buffer to 0
|
||||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||||
// Initialize values needed to form NTP request
|
// Initialize values needed to form NTP request
|
||||||
// (see URL above for details on the packets)
|
// (see URL above for details on the packets)
|
||||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||||
packetBuffer[2] = 6; // Polling Interval
|
packetBuffer[2] = 6; // Polling Interval
|
||||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||||
packetBuffer[12] = 49;
|
packetBuffer[12] = 49;
|
||||||
packetBuffer[13] = 0x4E;
|
packetBuffer[13] = 0x4E;
|
||||||
packetBuffer[14] = 49;
|
packetBuffer[14] = 49;
|
||||||
packetBuffer[15] = 52;
|
packetBuffer[15] = 52;
|
||||||
|
|
||||||
// all NTP fields have been given values, now
|
// all NTP fields have been given values, now
|
||||||
// you can send a packet requesting a timestamp:
|
// you can send a packet requesting a timestamp:
|
||||||
Udp.beginPacket(timeserver, 123); //NTP requests are to port 123
|
Udp.beginPacket(timeserver, 123); //NTP requests are to port 123
|
||||||
Udp.write(packetBuffer,NTP_PACKET_SIZE);
|
Udp.write(packetBuffer,NTP_PACKET_SIZE);
|
||||||
Udp.endPacket();
|
Udp.endPacket();
|
||||||
Serial.println("Sending ntp packet");
|
Serial.println("Sending ntp packet");
|
||||||
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
if ( Udp.parsePacket() ) {
|
if ( Udp.parsePacket() ) {
|
||||||
// We've received a packet, read the data from it
|
// We've received a packet, read the data from it
|
||||||
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
|
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer
|
||||||
|
|
||||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||||
// or two words, long. First, esxtract the two words:
|
// or two words, long. First, esxtract the two words:
|
||||||
|
|
||||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||||
// combine the four bytes (two words) into a long integer
|
// combine the four bytes (two words) into a long integer
|
||||||
// this is NTP time (seconds since Jan 1 1900):
|
// this is NTP time (seconds since Jan 1 1900):
|
||||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||||
const unsigned long seventyYears = 2208988800UL;
|
const unsigned long seventyYears = 2208988800UL;
|
||||||
// subtract seventy years:
|
// subtract seventy years:
|
||||||
unsigned long epoch = secsSince1900 - seventyYears + TIMEZONE;
|
unsigned long epoch = secsSince1900 - seventyYears + TIMEZONE;
|
||||||
|
|
||||||
Serial.println("Adjusting time");
|
Serial.println("Adjusting time");
|
||||||
chronodot.adjust(DateTime(epoch));
|
chronodot.adjust(DateTime(epoch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
pinMode(5, OUTPUT);
|
|
||||||
SPI.begin();
|
|
||||||
|
|
||||||
//----- Ethernet/WebServer
|
//----- Ethernet/WebServer
|
||||||
Serial.println("INIT Ethernet");
|
Serial.println("INIT Ethernet");
|
||||||
|
Loading…
Reference in New Issue
Block a user