Merge branch 'master' into development
Conflicts: libraries/MySensors/MySensor.cpp libraries/MySensors/examples/EthernetGateway/EthernetGateway.ino
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
/***************************************************
|
||||
This is a library for the BMP085 Barometric Pressure & Temp Sensor
|
||||
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
|
||||
|
||||
Designed specifically to work with the Adafruit BMP085 Breakout
|
||||
----> https://www.adafruit.com/products/391
|
||||
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||
----> http://www.adafruit.com/products/391
|
||||
----> http://www.adafruit.com/products/1603
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
@@ -15,7 +16,6 @@
|
||||
****************************************************/
|
||||
|
||||
#include "Adafruit_BMP085.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
Adafruit_BMP085::Adafruit_BMP085() {
|
||||
}
|
||||
@@ -59,11 +59,19 @@ boolean Adafruit_BMP085::begin(uint8_t mode) {
|
||||
Serial.print("mc = "); Serial.println(mc, DEC);
|
||||
Serial.print("md = "); Serial.println(md, DEC);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t Adafruit_BMP085::computeB5(int32_t UT) {
|
||||
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
|
||||
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
|
||||
return X1 + X2;
|
||||
}
|
||||
|
||||
uint16_t Adafruit_BMP085::readRawTemperature(void) {
|
||||
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
|
||||
_delay_ms(5);
|
||||
delay(5);
|
||||
#if BMP085_DEBUG == 1
|
||||
Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA));
|
||||
#endif
|
||||
@@ -76,13 +84,13 @@ uint32_t Adafruit_BMP085::readRawPressure(void) {
|
||||
write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
|
||||
|
||||
if (oversampling == BMP085_ULTRALOWPOWER)
|
||||
_delay_ms(5);
|
||||
delay(5);
|
||||
else if (oversampling == BMP085_STANDARD)
|
||||
_delay_ms(8);
|
||||
delay(8);
|
||||
else if (oversampling == BMP085_HIGHRES)
|
||||
_delay_ms(14);
|
||||
delay(14);
|
||||
else
|
||||
_delay_ms(26);
|
||||
delay(26);
|
||||
|
||||
raw = read16(BMP085_PRESSUREDATA);
|
||||
|
||||
@@ -129,10 +137,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
|
||||
oversampling = 0;
|
||||
#endif
|
||||
|
||||
// do temperature calculations
|
||||
X1=(UT-(int32_t)(ac6))*((int32_t)(ac5))/pow(2,15);
|
||||
X2=((int32_t)mc*pow(2,11))/(X1+(int32_t)md);
|
||||
B5=X1 + X2;
|
||||
B5 = computeB5(UT);
|
||||
|
||||
#if BMP085_DEBUG == 1
|
||||
Serial.print("X1 = "); Serial.println(X1);
|
||||
@@ -189,9 +194,13 @@ int32_t Adafruit_BMP085::readPressure(void) {
|
||||
return p;
|
||||
}
|
||||
|
||||
int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) {
|
||||
float pressure = readPressure();
|
||||
return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255));
|
||||
}
|
||||
|
||||
float Adafruit_BMP085::readTemperature(void) {
|
||||
int32_t UT, X1, X2, B5; // following ds convention
|
||||
int32_t UT, B5; // following ds convention
|
||||
float temp;
|
||||
|
||||
UT = readRawTemperature();
|
||||
@@ -205,11 +214,8 @@ float Adafruit_BMP085::readTemperature(void) {
|
||||
md = 2868;
|
||||
#endif
|
||||
|
||||
// step 1
|
||||
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2,15);
|
||||
X2 = ((int32_t)mc * pow(2,11)) / (X1+(int32_t)md);
|
||||
B5 = X1 + X2;
|
||||
temp = (B5+8)/pow(2,4);
|
||||
B5 = computeB5(UT);
|
||||
temp = (B5+8) >> 4;
|
||||
temp /= 10;
|
||||
|
||||
return temp;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/***************************************************
|
||||
This is a library for the BMP085 Barometric Pressure & Temp Sensor
|
||||
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
|
||||
|
||||
Designed specifically to work with the Adafruit BMP085 Breakout
|
||||
----> https://www.adafruit.com/products/391
|
||||
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||
----> http://www.adafruit.com/products/391
|
||||
----> http://www.adafruit.com/products/1603
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
@@ -14,6 +15,9 @@
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#ifndef ADAFRUIT_BMP085_H
|
||||
#define ADAFRUIT_BMP085_H
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
@@ -54,11 +58,13 @@ class Adafruit_BMP085 {
|
||||
boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
|
||||
float readTemperature(void);
|
||||
int32_t readPressure(void);
|
||||
int32_t readSealevelPressure(float altitude_meters = 0);
|
||||
float readAltitude(float sealevelPressure = 101325); // std atmosphere
|
||||
uint16_t readRawTemperature(void);
|
||||
uint32_t readRawPressure(void);
|
||||
|
||||
private:
|
||||
int32_t computeB5(int32_t UT);
|
||||
uint8_t read8(uint8_t addr);
|
||||
uint16_t read16(uint8_t addr);
|
||||
void write8(uint8_t addr, uint8_t data);
|
||||
@@ -69,3 +75,5 @@ class Adafruit_BMP085 {
|
||||
uint16_t ac4, ac5, ac6;
|
||||
};
|
||||
|
||||
|
||||
#endif // ADAFRUIT_BMP085_H
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
This is a library for the Adafruit BMP085 Barometric Pressure + Temp sensor
|
||||
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
|
||||
|
||||
Designed specifically to work with the Adafruit BMP085 Breakout
|
||||
----> https://www.adafruit.com/products/391
|
||||
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||
----> http://www.adafruit.com/products/391
|
||||
----> http://www.adafruit.com/products/1603
|
||||
|
||||
These displays use I2C to communicate, 2 pins are required to interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
@@ -17,6 +18,11 @@ products from Adafruit!
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
|
||||
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_BMP085. Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
|
||||
To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BMP085.
|
||||
Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
|
||||
|
||||
Place the Adafruit_BMP085 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
||||
Place the Adafruit_BMP085 library folder your arduinosketchfolder/libraries/ folder.
|
||||
You may need to create the libraries subfolder if its your first library. Restart the IDE.
|
||||
|
||||
We also have a great tutorial on Arduino library installation at:
|
||||
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
|
||||
// pick ONE of these - other board layouts can be easily added this way
|
||||
// #define MYSENSORS_SENSOR
|
||||
#define MYSENSORS_SERIAL_GATEWAY
|
||||
#define MYSENSORS_SENSOR
|
||||
//#define MYSENSORS_SERIAL_GATEWAY
|
||||
//#define MYSENSORS_ETHERNET_MQTT_GATEWAY
|
||||
|
||||
// Choose radio type by enabling one of the following
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
#ifndef Version_h
|
||||
#define Version_h
|
||||
|
||||
#define LIBRARY_VERSION "1.4"
|
||||
#define LIBRARY_VERSION "1.4.1"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
|
||||
*
|
||||
* Contribution by a-lurker and Anticimex
|
||||
* Contribution by a-lurker and Anticimex,
|
||||
* Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -14,15 +15,17 @@
|
||||
*
|
||||
* The GW code is designed for Arduino 328p / 16MHz. ATmega168 does not have enough memory to run this program.
|
||||
*
|
||||
* COMPILING ENC28J60
|
||||
*
|
||||
* COMPILING WIZNET (W5100) ETHERNET MODULE
|
||||
* > Edit RF24_config.h in (libraries\MySensors\utility) to enable softspi (remove // before "#define SOFTSPI").
|
||||
*
|
||||
* COMPILING ENC28J60 ETHERNET MODULE
|
||||
* > Use Arduino IDE 1.5.7 (or later)
|
||||
* > Disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch will probably not fit in program space when downloading.
|
||||
* > Remove Ethernet.h include below and inlcude UIPEthernet.h
|
||||
* COMPILING WizNET (W5100)
|
||||
* > Remove UIPEthernet include below and include Ethernet.h.
|
||||
* > Remove Ethernet.h include below and include UIPEthernet.h
|
||||
* > Remove DigitalIO include
|
||||
* Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which means you have to choose a static IP for that module)
|
||||
*
|
||||
* Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which meas you ave to choose a static IP for that module)
|
||||
|
||||
* VERA CONFIGURATION:
|
||||
* Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin.
|
||||
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
|
||||
@@ -32,24 +35,12 @@
|
||||
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
|
||||
* - ERR (red) - fast blink on error during transmission error or recieve crc error
|
||||
*
|
||||
* ----------- Connection guide ---------------------------------------------------------------------------
|
||||
* 13 Radio & Ethernet SPI SCK
|
||||
* 12 Radio & Ethernet SPI MISO (SO)
|
||||
* 11 Radio & Ethernet SPI MOSI (SI)
|
||||
* 10 Ethernet SPI Slave Select (CS) Pin 10, the SS pin, must be an o/p to put SPI in master mode
|
||||
* 9 Radio TX LED using on board LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 9.
|
||||
* 8 Radio RX LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 8.
|
||||
* 7 Radio error LED (optional) +5V -> LED -> 270-330 Ohm resistor -> pin 7.
|
||||
* 6 Radio SPI Slave Select
|
||||
* 5 Radio Chip Enable
|
||||
* 4 Ethernet SPI Enable (optional if using a shield/module that manages SPI_EN signal)
|
||||
* 3 Inclusion mode button (optional) GND-> Button -> Pin3
|
||||
* 2 Radio IRQ pin (optional)
|
||||
* -----------------------------------------------------------------------------------------------------------
|
||||
* Powering: both NRF24l01 radio and Ethernet(ENC28J60) uses 3.3V
|
||||
* See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
|
||||
*
|
||||
*/
|
||||
#define NO_PORTB_PINCHANGES
|
||||
|
||||
#include <DigitalIO.h> // This include can be removed when using UIPEthernet module
|
||||
#include <SPI.h>
|
||||
#include <MySensor.h>
|
||||
#include <stdarg.h>
|
||||
@@ -64,14 +55,13 @@
|
||||
// Use this if you have attached a Ethernet ENC28J60 shields
|
||||
//#include <UIPEthernet.h>
|
||||
|
||||
// Use this fo WizNET module and Arduino Ethernet Shield
|
||||
// Use this for WizNET W5100 module and Arduino Ethernet Shield
|
||||
#include <Ethernet.h>
|
||||
|
||||
|
||||
#define INCLUSION_MODE_TIME 1 // Number of minutes inclusion mode is enabled
|
||||
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
|
||||
|
||||
#define W5100_SPI_EN 4 // Ethernet SPI enable (where available)
|
||||
#define RADIO_CE_PIN 5 // radio chip enable
|
||||
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
|
||||
|
||||
@@ -93,47 +83,26 @@ byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // DEAD BEEF FEED
|
||||
|
||||
// a R/W server on the port
|
||||
EthernetServer server = EthernetServer(IP_PORT);
|
||||
|
||||
// handle to open connection
|
||||
EthernetClient client = EthernetClient();
|
||||
|
||||
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
|
||||
int inputPos = 0;
|
||||
bool sentReady = false;
|
||||
|
||||
void w5100_spi_en(boolean enable)
|
||||
{
|
||||
#ifdef W5100_SPI_EN
|
||||
if (enable)
|
||||
{
|
||||
// Pull up pin
|
||||
pinMode(W5100_SPI_EN, INPUT);
|
||||
digitalWrite(W5100_SPI_EN, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ground pin
|
||||
pinMode(W5100_SPI_EN, OUTPUT);
|
||||
digitalWrite(W5100_SPI_EN, LOW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void output(const char *fmt, ... ) {
|
||||
va_list args;
|
||||
va_start (args, fmt );
|
||||
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
|
||||
va_end (args);
|
||||
Serial.print(serialBuffer);
|
||||
w5100_spi_en(true);
|
||||
server.write(serialBuffer);
|
||||
w5100_spi_en(false);
|
||||
client.write(serialBuffer);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
w5100_spi_en(false);
|
||||
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
|
||||
gw.begin(incomingMessage, 0, true, 0);
|
||||
w5100_spi_en(true);
|
||||
|
||||
Ethernet.begin(mac, myIp);
|
||||
setupGateway(RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
|
||||
@@ -150,65 +119,61 @@ void setup()
|
||||
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
w5100_spi_en(false);
|
||||
|
||||
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
void loop() {
|
||||
gw.process();
|
||||
|
||||
|
||||
checkButtonTriggeredInclusion();
|
||||
checkInclusionFinished();
|
||||
|
||||
|
||||
// if an incoming client connects, there will be
|
||||
// bytes available to read via the client object
|
||||
w5100_spi_en(true);
|
||||
EthernetClient client = server.available();
|
||||
|
||||
if (client) {
|
||||
if (!sentReady) {
|
||||
// Send gateway startup message when first client connects
|
||||
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
|
||||
sentReady = true;
|
||||
}
|
||||
|
||||
// if got 1 or more bytes
|
||||
if (client.available()) {
|
||||
// read the bytes incoming from the client
|
||||
char inChar = client.read();
|
||||
if (inputPos<MAX_RECEIVE_LENGTH-1) {
|
||||
// if newline then command is complete
|
||||
if (inChar == '\n') {
|
||||
Serial.println("Finished");
|
||||
// a command was issued by the client
|
||||
// we will now try to send it to the actuator
|
||||
inputString[inputPos] = 0;
|
||||
|
||||
// echo the string to the serial port
|
||||
Serial.print(inputString);
|
||||
|
||||
w5100_spi_en(false);
|
||||
parseAndSend(gw, inputString);
|
||||
|
||||
// clear the string:
|
||||
inputPos = 0;
|
||||
} else {
|
||||
// add it to the inputString:
|
||||
inputString[inputPos] = inChar;
|
||||
inputPos++;
|
||||
}
|
||||
} else {
|
||||
// Incoming message too long. Throw away
|
||||
inputPos = 0;
|
||||
}
|
||||
EthernetClient newclient = server.available();
|
||||
// if a new client connects make sure to dispose any previous existing sockets
|
||||
if (newclient) {
|
||||
if (client != newclient) {
|
||||
client.stop();
|
||||
client = newclient;
|
||||
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
|
||||
}
|
||||
}
|
||||
|
||||
if (client) {
|
||||
if (!client.connected()) {
|
||||
client.stop();
|
||||
} else if (client.available()) {
|
||||
// read the bytes incoming from the client
|
||||
char inChar = client.read();
|
||||
if (inputPos<MAX_RECEIVE_LENGTH-1) {
|
||||
// if newline then command is complete
|
||||
if (inChar == '\n') {
|
||||
Serial.println("Finished");
|
||||
// a command was issued by the client
|
||||
// we will now try to send it to the actuator
|
||||
inputString[inputPos] = 0;
|
||||
|
||||
// echo the string to the serial port
|
||||
Serial.print(inputString);
|
||||
|
||||
parseAndSend(gw, inputString);
|
||||
|
||||
// clear the string:
|
||||
inputPos = 0;
|
||||
} else {
|
||||
// add it to the inputString:
|
||||
inputString[inputPos] = inChar;
|
||||
inputPos++;
|
||||
}
|
||||
} else {
|
||||
// Incoming message too long. Throw away
|
||||
inputPos = 0;
|
||||
}
|
||||
}
|
||||
w5100_spi_en(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
float pressure = bmp.readPressure()/100;
|
||||
float pressure = bmp.readSealevelPressure(205)/100; // 205 meters above sealevel
|
||||
float temperature = bmp.readTemperature();
|
||||
|
||||
if (!metric) {
|
||||
@@ -95,16 +95,16 @@ void loop() {
|
||||
int sample(float pressure) {
|
||||
// Algorithm found here
|
||||
// http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
|
||||
if (minuteCount > 180)
|
||||
minuteCount = 6;
|
||||
if (minuteCount == 180)
|
||||
minuteCount = 5;
|
||||
|
||||
pressureSamples[minuteCount] = pressure;
|
||||
minuteCount++;
|
||||
|
||||
if (minuteCount == 5) {
|
||||
// Avg pressure in first 5 min, value averaged from 0 to 5 min.
|
||||
pressureAvg[0] = ((pressureSamples[1] + pressureSamples[2]
|
||||
+ pressureSamples[3] + pressureSamples[4] + pressureSamples[5])
|
||||
pressureAvg[0] = ((pressureSamples[0] + pressureSamples[1]
|
||||
+ pressureSamples[2] + pressureSamples[3] + pressureSamples[4])
|
||||
/ 5);
|
||||
} else if (minuteCount == 35) {
|
||||
// Avg pressure in 30 min, value averaged from 0 to 5 min.
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user