initial upload
This commit is contained in:
parent
9a2494583d
commit
dfd8fdec4a
35 changed files with 2616 additions and 0 deletions
175
examples/osd/arduino-bmp085/Barometer.cpp
Normal file
175
examples/osd/arduino-bmp085/Barometer.cpp
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
Barometer library V1.0
|
||||
2010 Copyright (c) Seeed Technology Inc. All right reserved.
|
||||
|
||||
Original Author: LG
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "Barometer.h"
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
void Barometer::init(void)
|
||||
{
|
||||
Wire.begin();
|
||||
// Serial.print("Temperaturet: ");
|
||||
ac1 = bmp085ReadInt(0xAA);
|
||||
ac2 = bmp085ReadInt(0xAC);
|
||||
ac3 = bmp085ReadInt(0xAE);
|
||||
ac4 = bmp085ReadInt(0xB0);
|
||||
ac5 = bmp085ReadInt(0xB2);
|
||||
ac6 = bmp085ReadInt(0xB4);
|
||||
b1 = bmp085ReadInt(0xB6);
|
||||
b2 = bmp085ReadInt(0xB8);
|
||||
mb = bmp085ReadInt(0xBA);
|
||||
mc = bmp085ReadInt(0xBC);
|
||||
md = bmp085ReadInt(0xBE);
|
||||
// Serial.print("Temperaturet2: ");
|
||||
}
|
||||
// Read 1 byte from the BMP085 at 'address'
|
||||
// Return: the read byte;
|
||||
char Barometer::bmp085Read(unsigned char address)
|
||||
{
|
||||
//Wire.begin();
|
||||
//unsigned char data;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(address);
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(BMP085_ADDRESS, 1);
|
||||
while(!Wire.available());
|
||||
return Wire.read();
|
||||
}
|
||||
// Read 2 bytes from the BMP085
|
||||
// First byte will be from 'address'
|
||||
// Second byte will be from 'address'+1
|
||||
int Barometer::bmp085ReadInt(unsigned char address)
|
||||
{
|
||||
unsigned char msb, lsb;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(address);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(BMP085_ADDRESS, 2);
|
||||
while(Wire.available()<2);
|
||||
msb = Wire.read();
|
||||
lsb = Wire.read();
|
||||
return (int) msb<<8 | lsb;
|
||||
}
|
||||
// Read the uncompensated temperature value
|
||||
unsigned int Barometer::bmp085ReadUT()
|
||||
{
|
||||
unsigned int ut;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(0xF4);
|
||||
Wire.write(0x2E);
|
||||
Wire.endTransmission();
|
||||
delay(5);
|
||||
ut = bmp085ReadInt(0xF6);
|
||||
return ut;
|
||||
}
|
||||
// Read the uncompensated pressure value
|
||||
unsigned long Barometer::bmp085ReadUP()
|
||||
{
|
||||
unsigned char msb, lsb, xlsb;
|
||||
unsigned long up = 0;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(0xF4);
|
||||
Wire.write(0x34 + (OSS<<6));
|
||||
Wire.endTransmission();
|
||||
delay(2 + (3<<OSS));
|
||||
|
||||
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
|
||||
msb = bmp085Read(0xF6);
|
||||
lsb = bmp085Read(0xF7);
|
||||
xlsb = bmp085Read(0xF8);
|
||||
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
|
||||
return up;
|
||||
}
|
||||
void Barometer::writeRegister(int deviceAddress, byte address, byte val)
|
||||
{
|
||||
Wire.beginTransmission(deviceAddress); // start transmission to device
|
||||
Wire.write(address); // send register address
|
||||
Wire.write(val); // send value to write
|
||||
Wire.endTransmission(); // end transmission
|
||||
}
|
||||
int Barometer::readRegister(int deviceAddress, byte address)
|
||||
{
|
||||
int v;
|
||||
Wire.beginTransmission(deviceAddress);
|
||||
Wire.write(address); // register to read
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(deviceAddress, 1); // read a byte
|
||||
|
||||
while(!Wire.available()) {
|
||||
// waiting
|
||||
}
|
||||
|
||||
v = Wire.read();
|
||||
return v;
|
||||
}
|
||||
float Barometer::calcAltitude(float pressure)
|
||||
{
|
||||
float A = pressure/101325;
|
||||
float B = 1/5.25588;
|
||||
float C = pow(A,B);
|
||||
C = 1 - C;
|
||||
C = C /0.0000225577;
|
||||
return C;
|
||||
}
|
||||
float Barometer::bmp085GetTemperature(unsigned int ut)
|
||||
{
|
||||
long x1, x2;
|
||||
|
||||
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
|
||||
x2 = ((long)mc << 11)/(x1 + md);
|
||||
PressureCompensate = x1 + x2;
|
||||
|
||||
float temp = ((PressureCompensate + 8)>>4);
|
||||
temp = temp /10;
|
||||
|
||||
return temp;
|
||||
}
|
||||
long Barometer::bmp085GetPressure(unsigned long up)
|
||||
{
|
||||
long x1, x2, x3, b3, b6, p;
|
||||
unsigned long b4, b7;
|
||||
b6 = PressureCompensate - 4000;
|
||||
x1 = (b2 * (b6 * b6)>>12)>>11;
|
||||
x2 = (ac2 * b6)>>11;
|
||||
x3 = x1 + x2;
|
||||
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
|
||||
|
||||
// Calculate B4
|
||||
x1 = (ac3 * b6)>>13;
|
||||
x2 = (b1 * ((b6 * b6)>>12))>>16;
|
||||
x3 = ((x1 + x2) + 2)>>2;
|
||||
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
|
||||
|
||||
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
|
||||
if (b7 < 0x80000000)
|
||||
p = (b7<<1)/b4;
|
||||
else
|
||||
p = (b7/b4)<<1;
|
||||
|
||||
x1 = (p>>8) * (p>>8);
|
||||
x1 = (x1 * 3038)>>16;
|
||||
x2 = (-7357 * p)>>16;
|
||||
p += (x1 + x2 + 3791)>>4;
|
||||
|
||||
long temp = p;
|
||||
return temp;
|
||||
}
|
58
examples/osd/arduino-bmp085/Barometer.h
Normal file
58
examples/osd/arduino-bmp085/Barometer.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Barometer library V1.0
|
||||
2010 Copyright (c) Seeed Technology Inc. All right reserved.
|
||||
|
||||
Original Author: LG
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef __BAROMETER_H__
|
||||
#define __BAROMETER_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
const unsigned char OSS = 0;
|
||||
#define BMP085_ADDRESS 0x77
|
||||
class Barometer
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
long PressureCompensate;
|
||||
float bmp085GetTemperature(unsigned int ut);
|
||||
long bmp085GetPressure(unsigned long up);
|
||||
float calcAltitude(float pressure);
|
||||
unsigned int bmp085ReadUT(void);
|
||||
unsigned long bmp085ReadUP(void);
|
||||
|
||||
private:
|
||||
int ac1;
|
||||
int ac2;
|
||||
int ac3;
|
||||
unsigned int ac4;
|
||||
unsigned int ac5;
|
||||
unsigned int ac6;
|
||||
int b1;
|
||||
int b2;
|
||||
int mb;
|
||||
int mc;
|
||||
int md;
|
||||
char bmp085Read(unsigned char address);
|
||||
int bmp085ReadInt(unsigned char address);
|
||||
void writeRegister(int deviceAddress, byte address, byte val);
|
||||
int readRegister(int deviceAddress, byte address);
|
||||
};
|
||||
|
||||
#endif
|
175
examples/osd/arduino-bmp085/Barometer_Sensor/Barometer.cpp
Normal file
175
examples/osd/arduino-bmp085/Barometer_Sensor/Barometer.cpp
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
Barometer library V1.0
|
||||
2010 Copyright (c) Seeed Technology Inc. All right reserved.
|
||||
|
||||
Original Author: LG
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "Barometer.h"
|
||||
#include <Wire.h>
|
||||
#include <Arduino.h>
|
||||
|
||||
void Barometer::init(void)
|
||||
{
|
||||
Wire.begin();
|
||||
Serial.print("Temperaturet: ");
|
||||
ac1 = bmp085ReadInt(0xAA);
|
||||
ac2 = bmp085ReadInt(0xAC);
|
||||
ac3 = bmp085ReadInt(0xAE);
|
||||
ac4 = bmp085ReadInt(0xB0);
|
||||
ac5 = bmp085ReadInt(0xB2);
|
||||
ac6 = bmp085ReadInt(0xB4);
|
||||
b1 = bmp085ReadInt(0xB6);
|
||||
b2 = bmp085ReadInt(0xB8);
|
||||
mb = bmp085ReadInt(0xBA);
|
||||
mc = bmp085ReadInt(0xBC);
|
||||
md = bmp085ReadInt(0xBE);
|
||||
Serial.print("Temperaturet2: ");
|
||||
}
|
||||
// Read 1 byte from the BMP085 at 'address'
|
||||
// Return: the read byte;
|
||||
char Barometer::bmp085Read(unsigned char address)
|
||||
{
|
||||
//Wire.begin();
|
||||
unsigned char data;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(address);
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(BMP085_ADDRESS, 1);
|
||||
while(!Wire.available());
|
||||
return Wire.read();
|
||||
}
|
||||
// Read 2 bytes from the BMP085
|
||||
// First byte will be from 'address'
|
||||
// Second byte will be from 'address'+1
|
||||
int Barometer::bmp085ReadInt(unsigned char address)
|
||||
{
|
||||
unsigned char msb, lsb;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(address);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(BMP085_ADDRESS, 2);
|
||||
while(Wire.available()<2);
|
||||
msb = Wire.read();
|
||||
lsb = Wire.read();
|
||||
return (int) msb<<8 | lsb;
|
||||
}
|
||||
// Read the uncompensated temperature value
|
||||
unsigned int Barometer::bmp085ReadUT()
|
||||
{
|
||||
unsigned int ut;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(0xF4);
|
||||
Wire.write(0x2E);
|
||||
Wire.endTransmission();
|
||||
delay(5);
|
||||
ut = bmp085ReadInt(0xF6);
|
||||
return ut;
|
||||
}
|
||||
// Read the uncompensated pressure value
|
||||
unsigned long Barometer::bmp085ReadUP()
|
||||
{
|
||||
unsigned char msb, lsb, xlsb;
|
||||
unsigned long up = 0;
|
||||
Wire.beginTransmission(BMP085_ADDRESS);
|
||||
Wire.write(0xF4);
|
||||
Wire.write(0x34 + (OSS<<6));
|
||||
Wire.endTransmission();
|
||||
delay(2 + (3<<OSS));
|
||||
|
||||
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
|
||||
msb = bmp085Read(0xF6);
|
||||
lsb = bmp085Read(0xF7);
|
||||
xlsb = bmp085Read(0xF8);
|
||||
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
|
||||
return up;
|
||||
}
|
||||
void Barometer::writeRegister(int deviceAddress, byte address, byte val)
|
||||
{
|
||||
Wire.beginTransmission(deviceAddress); // start transmission to device
|
||||
Wire.write(address); // send register address
|
||||
Wire.write(val); // send value to write
|
||||
Wire.endTransmission(); // end transmission
|
||||
}
|
||||
int Barometer::readRegister(int deviceAddress, byte address)
|
||||
{
|
||||
int v;
|
||||
Wire.beginTransmission(deviceAddress);
|
||||
Wire.write(address); // register to read
|
||||
Wire.endTransmission();
|
||||
|
||||
Wire.requestFrom(deviceAddress, 1); // read a byte
|
||||
|
||||
while(!Wire.available()) {
|
||||
// waiting
|
||||
}
|
||||
|
||||
v = Wire.read();
|
||||
return v;
|
||||
}
|
||||
float Barometer::calcAltitude(float pressure)
|
||||
{
|
||||
float A = pressure/101325;
|
||||
float B = 1/5.25588;
|
||||
float C = pow(A,B);
|
||||
C = 1 - C;
|
||||
C = C /0.0000225577;
|
||||
return C;
|
||||
}
|
||||
float Barometer::bmp085GetTemperature(unsigned int ut)
|
||||
{
|
||||
long x1, x2;
|
||||
|
||||
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
|
||||
x2 = ((long)mc << 11)/(x1 + md);
|
||||
PressureCompensate = x1 + x2;
|
||||
|
||||
float temp = ((PressureCompensate + 8)>>4);
|
||||
temp = temp /10;
|
||||
|
||||
return temp;
|
||||
}
|
||||
long Barometer::bmp085GetPressure(unsigned long up)
|
||||
{
|
||||
long x1, x2, x3, b3, b6, p;
|
||||
unsigned long b4, b7;
|
||||
b6 = PressureCompensate - 4000;
|
||||
x1 = (b2 * (b6 * b6)>>12)>>11;
|
||||
x2 = (ac2 * b6)>>11;
|
||||
x3 = x1 + x2;
|
||||
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
|
||||
|
||||
// Calculate B4
|
||||
x1 = (ac3 * b6)>>13;
|
||||
x2 = (b1 * ((b6 * b6)>>12))>>16;
|
||||
x3 = ((x1 + x2) + 2)>>2;
|
||||
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
|
||||
|
||||
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
|
||||
if (b7 < 0x80000000)
|
||||
p = (b7<<1)/b4;
|
||||
else
|
||||
p = (b7/b4)<<1;
|
||||
|
||||
x1 = (p>>8) * (p>>8);
|
||||
x1 = (x1 * 3038)>>16;
|
||||
x2 = (-7357 * p)>>16;
|
||||
p += (x1 + x2 + 3791)>>4;
|
||||
|
||||
long temp = p;
|
||||
return temp;
|
||||
}
|
58
examples/osd/arduino-bmp085/Barometer_Sensor/Barometer.h
Normal file
58
examples/osd/arduino-bmp085/Barometer_Sensor/Barometer.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Barometer library V1.0
|
||||
2010 Copyright (c) Seeed Technology Inc. All right reserved.
|
||||
|
||||
Original Author: LG
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef __BAROMETER_H__
|
||||
#define __BAROMETER_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
const unsigned char OSS = 0;
|
||||
#define BMP085_ADDRESS 0x77
|
||||
class Barometer
|
||||
{
|
||||
public:
|
||||
void init(void);
|
||||
long PressureCompensate;
|
||||
float bmp085GetTemperature(unsigned int ut);
|
||||
long bmp085GetPressure(unsigned long up);
|
||||
float calcAltitude(float pressure);
|
||||
unsigned int bmp085ReadUT(void);
|
||||
unsigned long bmp085ReadUP(void);
|
||||
|
||||
private:
|
||||
int ac1;
|
||||
int ac2;
|
||||
int ac3;
|
||||
unsigned int ac4;
|
||||
unsigned int ac5;
|
||||
unsigned int ac6;
|
||||
int b1;
|
||||
int b2;
|
||||
int mb;
|
||||
int mc;
|
||||
int md;
|
||||
char bmp085Read(unsigned char address);
|
||||
int bmp085ReadInt(unsigned char address);
|
||||
void writeRegister(int deviceAddress, byte address, byte val);
|
||||
int readRegister(int deviceAddress, byte address);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,49 @@
|
|||
/* Barometer demo V1.0
|
||||
* Based largely on code by Jim Lindblom
|
||||
* Get pressure, altitude, and temperature from the BMP085.
|
||||
* Serial.print it out at 9600 baud to serial monitor.
|
||||
*
|
||||
* By:http://www.seeedstudio.com
|
||||
*/
|
||||
#include "Barometer.h"
|
||||
#include <Wire.h>
|
||||
float temperature;
|
||||
float pressure;
|
||||
float atm;
|
||||
float altitude;
|
||||
Barometer myBarometer;
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
myBarometer.init();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
temperature = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first
|
||||
pressure = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());//Get the temperature
|
||||
altitude = myBarometer.calcAltitude(pressure); //Uncompensated caculation - in Meters
|
||||
atm = pressure / 101325;
|
||||
|
||||
Serial.print("Temperature: ");
|
||||
Serial.print(temperature, 2); //display 2 decimal places
|
||||
Serial.println("deg C");
|
||||
|
||||
Serial.print("Pressure: ");
|
||||
Serial.print(pressure, 0); //whole number only.
|
||||
Serial.println(" Pa");
|
||||
|
||||
Serial.print("Ralated Atmosphere: ");
|
||||
Serial.println(atm, 4); //display 4 decimal places
|
||||
|
||||
Serial.print("Altitude: ");
|
||||
Serial.print(altitude, 2); //display 2 decimal places
|
||||
Serial.println(" m");
|
||||
|
||||
Serial.println();
|
||||
|
||||
delay(1000); //wait a second and get values again.
|
||||
}
|
||||
|
||||
|
||||
|
71
examples/osd/arduino-bmp085/Makefile
Normal file
71
examples/osd/arduino-bmp085/Makefile
Normal file
|
@ -0,0 +1,71 @@
|
|||
# Set this to the name of your sketch (without extension .pde)
|
||||
SKETCH=sketch
|
||||
EXE=arduino-example
|
||||
|
||||
all: $(EXE)
|
||||
|
||||
CONTIKI=../../..
|
||||
|
||||
# Contiki IPv6 configuration
|
||||
CONTIKI_WITH_IPV6 = 1
|
||||
|
||||
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
|
||||
LFLAGS += -lm
|
||||
|
||||
PROJECT_SOURCEFILES += ${SKETCH}.cpp Barometer.cpp
|
||||
|
||||
# automatically build RESTful resources
|
||||
REST_RESOURCES_DIR = ./resources
|
||||
REST_RESOURCES_DIR_COMMON = ../resources-common
|
||||
REST_RESOURCES_FILES= $(notdir \
|
||||
$(shell find $(REST_RESOURCES_DIR) -name '*.c') \
|
||||
$(shell find $(REST_RESOURCES_DIR_COMMON) -name '*.c') \
|
||||
)
|
||||
|
||||
PROJECTDIRS += $(REST_RESOURCES_DIR) $(REST_RESOURCES_DIR_COMMON)
|
||||
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
|
||||
|
||||
# variable for Makefile.include
|
||||
ifneq ($(TARGET), minimal-net)
|
||||
CFLAGS += -DUIP_CONF_IPV6_RPL=1
|
||||
else
|
||||
# minimal-net does not support RPL under Linux and is mostly used to test CoAP only
|
||||
${info INFO: compiling without RPL}
|
||||
CFLAGS += -DUIP_CONF_IPV6_RPL=0
|
||||
CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\"
|
||||
${info INFO: compiling with large buffers}
|
||||
CFLAGS += -DUIP_CONF_BUFFER_SIZE=2048
|
||||
CFLAGS += -DREST_MAX_CHUNK_SIZE=1024
|
||||
CFLAGS += -DCOAP_MAX_HEADER_SIZE=640
|
||||
endif
|
||||
|
||||
# linker optimizations
|
||||
SMALL=1
|
||||
|
||||
|
||||
# REST Engine shall use Erbium CoAP implementation
|
||||
APPS += er-coap
|
||||
APPS += rest-engine
|
||||
APPS += arduino
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
||||
include $(CONTIKI)/apps/arduino/Makefile.include
|
||||
|
||||
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
|
||||
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
|
||||
|
||||
connect-router: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
|
||||
|
||||
connect-router-cooja: $(CONTIKI)/tools/tunslip6
|
||||
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/64
|
||||
|
||||
connect-minimal:
|
||||
sudo ip address add fdfd::1/64 dev tap0
|
||||
|
||||
avr-size: $(EXE).$(TARGET).sz
|
||||
|
||||
flash: $(EXE).$(TARGET).u $(EXE).$(TARGET).eu
|
||||
|
||||
.PHONY: flash avr-size
|
||||
.PRECIOUS: $(EXE).$(TARGET).hex $(EXE).$(TARGET).eep
|
11
examples/osd/arduino-bmp085/README.md
Normal file
11
examples/osd/arduino-bmp085/README.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
Arduino compatibility example
|
||||
=============================
|
||||
|
||||
This example shows that it is now possible to re-use arduino sketches in
|
||||
Contiki. This example documents the necessary magic. Arduino specifies
|
||||
two routines, `setup` and `loop`. Before `setup` is called, the
|
||||
framework initializes hardware. In original Arduino, all this is done in
|
||||
a `main` function (in C). For contiki we define a process that does the
|
||||
same.
|
||||
|
||||
See the documentation file in apps/contiki-compat/README.md
|
2
examples/osd/arduino-bmp085/arduino-example.c
Normal file
2
examples/osd/arduino-bmp085/arduino-example.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include <arduino-process.h>
|
||||
AUTOSTART_PROCESSES(&arduino_sketch);
|
2
examples/osd/arduino-bmp085/flash.sh
Executable file
2
examples/osd/arduino-bmp085/flash.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
make TARGET=osd-merkur-128 flash
|
106
examples/osd/arduino-bmp085/project-conf.h
Normal file
106
examples/osd/arduino-bmp085/project-conf.h
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROJECT_RPL_WEB_CONF_H_
|
||||
#define PROJECT_RPL_WEB_CONF_H_
|
||||
|
||||
#define PLATFORM_HAS_LEDS 1
|
||||
//#define PLATFORM_HAS_BUTTON 1
|
||||
#define PLATFORM_HAS_BATTERY 1
|
||||
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
|
||||
#define LOOP_INTERVAL (10 * CLOCK_SECOND)
|
||||
|
||||
/* Save energy */
|
||||
//#define RDC_CONF_PT_YIELD_OFF
|
||||
|
||||
/* For Debug: Dont allow MCU sleeping between channel checks */
|
||||
//#undef RDC_CONF_MCU_SLEEP
|
||||
//#define RDC_CONF_MCU_SLEEP 0
|
||||
|
||||
/* Disabling RDC for demo purposes. Core updates often require more memory. */
|
||||
/* For projects, optimize memory and enable RDC again. */
|
||||
// #undef NETSTACK_CONF_RDC
|
||||
//#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
/* Increase rpl-border-router IP-buffer when using more than 64. */
|
||||
#undef REST_MAX_CHUNK_SIZE
|
||||
#define REST_MAX_CHUNK_SIZE 64
|
||||
|
||||
/* Estimate your header size, especially when using Proxy-Uri. */
|
||||
/*
|
||||
#undef COAP_MAX_HEADER_SIZE
|
||||
#define COAP_MAX_HEADER_SIZE 70
|
||||
*/
|
||||
|
||||
/* The IP buffer size must fit all other hops, in particular the border router. */
|
||||
|
||||
#undef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 256
|
||||
|
||||
|
||||
/* Multiplies with chunk size, be aware of memory constraints. */
|
||||
#undef COAP_MAX_OPEN_TRANSACTIONS
|
||||
#define COAP_MAX_OPEN_TRANSACTIONS 4
|
||||
|
||||
/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
|
||||
/*
|
||||
#undef COAP_MAX_OBSERVERS
|
||||
#define COAP_MAX_OBSERVERS 2
|
||||
*/
|
||||
|
||||
/* Filtering .well-known/core per query can be disabled to save space. */
|
||||
/*
|
||||
#undef COAP_LINK_FORMAT_FILTERING
|
||||
#define COAP_LINK_FORMAT_FILTERING 0
|
||||
*/
|
||||
|
||||
/* Save some memory for the sky platform. */
|
||||
/*
|
||||
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
|
||||
#undef UIP_CONF_MAX_ROUTES
|
||||
#define UIP_CONF_MAX_ROUTES 10
|
||||
*/
|
||||
|
||||
/* Reduce 802.15.4 frame queue to save RAM. */
|
||||
/*
|
||||
#undef QUEUEBUF_CONF_NUM
|
||||
#define QUEUEBUF_CONF_NUM 4
|
||||
*/
|
||||
|
||||
/*
|
||||
#undef SICSLOWPAN_CONF_FRAG
|
||||
#define SICSLOWPAN_CONF_FRAG 1
|
||||
*/
|
||||
|
||||
#endif /* PROJECT_RPL_WEB_CONF_H_ */
|
79
examples/osd/arduino-bmp085/resources/res-bmp085alt.c
Normal file
79
examples/osd/arduino-bmp085/resources/res-bmp085alt.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Barometer resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_bmp085alt,
|
||||
"title=\"alt status\";rt=\"alt\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern char bmp085alt_s[8];
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", bmp085alt_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'temperature':%s}", bmp085alt_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
79
examples/osd/arduino-bmp085/resources/res-bmp085atm.c
Normal file
79
examples/osd/arduino-bmp085/resources/res-bmp085atm.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Barometer resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_bmp085atm,
|
||||
"title=\"atm status\";rt=\"atm\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern char bmp085atm_s[8];
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", bmp085atm_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'temperature':%s}", bmp085atm_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
79
examples/osd/arduino-bmp085/resources/res-bmp085press.c
Normal file
79
examples/osd/arduino-bmp085/resources/res-bmp085press.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Barometer resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_bmp085press,
|
||||
"title=\"pressure status\";rt=\"pressure\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern char bmp085press_s[8];
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", bmp085press_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'pressure':%s}", bmp085press_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
79
examples/osd/arduino-bmp085/resources/res-bmp085temp.c
Normal file
79
examples/osd/arduino-bmp085/resources/res-bmp085temp.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Barometer resource
|
||||
* \author
|
||||
* Harald Pichler <harald@the-develop.net>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "rest-engine.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset);
|
||||
|
||||
/* A simple getter example. Returns the reading from the sensor with a simple etag */
|
||||
RESOURCE(res_bmp085temp,
|
||||
"title=\"Temperature status\";rt=\"Temperatur\"",
|
||||
res_get_handler,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
extern char bmp085temp_s[8];
|
||||
|
||||
static void
|
||||
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||
{
|
||||
|
||||
unsigned int accept = -1;
|
||||
REST.get_header_accept(request, &accept);
|
||||
|
||||
if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
|
||||
REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%s", bmp085temp_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else if(accept == REST.type.APPLICATION_JSON) {
|
||||
REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
|
||||
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'temperature':%s}", bmp085temp_s);
|
||||
|
||||
REST.set_response_payload(response, buffer, strlen((char *)buffer));
|
||||
} else {
|
||||
REST.set_response_status(response, REST.status.NOT_ACCEPTABLE);
|
||||
const char *msg = "Supporting content-types text/plain and application/json";
|
||||
REST.set_response_payload(response, msg, strlen(msg));
|
||||
}
|
||||
}
|
5
examples/osd/arduino-bmp085/run.sh
Executable file
5
examples/osd/arduino-bmp085/run.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
# For the ages-old bootloader (before 2014) you want to use
|
||||
# BOOTLOADER_GET_MAC=0x0001f3a0 as parameter to make below.
|
||||
make clean TARGET=osd-merkur-128
|
||||
make TARGET=osd-merkur-128
|
86
examples/osd/arduino-bmp085/sketch.pde
Normal file
86
examples/osd/arduino-bmp085/sketch.pde
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Sample arduino sketch using contiki features.
|
||||
* We turn the LED off
|
||||
* We allow read the moisture sensor
|
||||
* Unfortunately sleeping for long times in loop() isn't currently
|
||||
* possible, something turns off the CPU (including PWM outputs) if a
|
||||
* Proto-Thread is taking too long. We need to find out how to sleep in
|
||||
* a Contiki-compatible way.
|
||||
* Note that for a normal arduino sketch you won't have to include any
|
||||
* of the contiki-specific files here, the sketch should just work.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "Barometer.h"
|
||||
|
||||
extern "C" {
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern resource_t res_bmp085temp,res_bmp085press,res_bmp085atm,res_bmp085alt, res_battery;
|
||||
|
||||
float bmp085temp;
|
||||
float bmp085press;
|
||||
float bmp085atm;
|
||||
float bmp085alt;
|
||||
char bmp085temp_s[8];
|
||||
char bmp085press_s[8];
|
||||
char bmp085atm_s[8];
|
||||
char bmp085alt_s[8];
|
||||
|
||||
Barometer myBarometer;
|
||||
|
||||
#define LED_PIN 4
|
||||
}
|
||||
|
||||
void setup (void)
|
||||
{
|
||||
// switch off the led
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
// BMP085 sensor
|
||||
myBarometer.init();
|
||||
// init coap resourcen
|
||||
rest_init_engine ();
|
||||
rest_activate_resource (&res_bmp085temp, "s/temp");
|
||||
rest_activate_resource (&res_bmp085press, "s/press");
|
||||
rest_activate_resource (&res_bmp085atm, "s/atm");
|
||||
rest_activate_resource (&res_bmp085alt, "s/alt");
|
||||
rest_activate_resource (&res_battery, "s/battery");
|
||||
}
|
||||
|
||||
// at project-conf.h
|
||||
// LOOP_INTERVAL (10 * CLOCK_SECOND)
|
||||
void loop (void)
|
||||
{
|
||||
mcu_sleep_off();
|
||||
bmp085temp = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first
|
||||
bmp085press = myBarometer.bmp085GetPressure(myBarometer.bmp085ReadUP());//Get the temperature
|
||||
bmp085alt = myBarometer.calcAltitude(bmp085press); //Uncompensated caculation - in Meters
|
||||
bmp085atm = bmp085press / 101325;
|
||||
|
||||
dtostrf(bmp085temp , 6, 2, bmp085temp_s );
|
||||
dtostrf(bmp085press , 6, 2, bmp085press_s );
|
||||
dtostrf(bmp085alt , 6, 2, bmp085alt_s );
|
||||
dtostrf(bmp085atm , 6, 2, bmp085atm_s );
|
||||
// remove space
|
||||
if(bmp085temp_s[0]==' '){
|
||||
memcpy (bmp085temp_s,bmp085temp_s+1,strlen(bmp085temp_s)+1);
|
||||
}
|
||||
if(bmp085press_s[0]==' '){
|
||||
memcpy (bmp085press_s,bmp085press_s+1,strlen(bmp085press_s)+1);
|
||||
}
|
||||
if(bmp085alt_s[0]==' '){
|
||||
memcpy (bmp085alt_s,bmp085alt_s+1,strlen(bmp085alt_s)+1);
|
||||
}
|
||||
if(bmp085atm_s[0]==' '){
|
||||
memcpy (bmp085atm_s,bmp085atm_s+1,strlen(bmp085atm_s)+1);
|
||||
}
|
||||
|
||||
// Debug Print
|
||||
printf("Temp: %s",bmp085temp_s);
|
||||
printf("\t\tPress: %s\n",bmp085press_s);
|
||||
printf("\t\tAltitude: %s\n",bmp085alt_s);
|
||||
printf("\t\tatm: %s\n",bmp085atm_s);
|
||||
mcu_sleep_on();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue