I have set up a nano board with the DHT22 sensor and the wireless radio… Since the reside in the same room… I am hoping to be able load both the gateway and HumiditySensor.ino files on the board. I merged the code from both the provided .INO files but it doesn’t work…
can any tell me if I am even wasting my time:
[code]/*
- Copyright (C) 2013 Henrik Ekblad henrik.ekblad@gmail.com
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
- DESCRIPTION
- The ArduinoGateway prints data received from sensors on the serial link.
- The gateway accepts input on seral which will be sent out on radio network.
- The GW code is designed for Arduino Nano 328p / 16MHz
- Wire connections (OPTIONAL):
-
- Inclusion button should be connected between digital pin 3 and GND
-
- RX/TX/ERR leds need to be connected between +5V (anode) and digital ping 6/5/4 with resistor 270-330R in a series
- LED purposes:
-
- RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
-
- 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
*/
- ERR (red) - fast blink on error during transmission error or recieve crc error
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <MsTimer2.h>
#include <PinChangeInt.h>
#include <Gateway.h>
#include <stdarg.h>
#include <avr/progmem.h>
#include <Sensor.h>
#include <DHT.h>
#include <Sleep_n0m1.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
// Set RADIO_ID to something unique in your sensor network (1-254)
// or set to AUTO if you want gw to assign a RADIO_ID for you.
#define RADIO_ID AUTO
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
DHT dht;
Sleep sleep;
float lastTemp;
float lastHum;
// Start gateway with include button and led blinking functionality enabled (see documetation)
//Gateway gw(9, 10, INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, 6, 5, 4);
// If blink and include mode button not is used uncomment and use below constructor instead
Gateway gw(9, 10, INCLUSION_MODE_TIME);
// Sensor gw(9, 10);
String inputString = “”; // A string to hold incoming commands from serial interface
boolean commandComplete = false; // whether the string is complete
void setup()
{
Serial.begin(BAUD_RATE); // Used to type in characters
gw.begin(RADIO_ID);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Register all sensors to gw (they will be created as child devices)
gw.sendSensorPresentation(CHILD_ID_HUM, S_HUM);
gw.sendSensorPresentation(CHILD_ID_TEMP, S_TEMP);
// reserve bytes for the inputString. RadioId;ChildId;VAR=VALUE
inputString.reserve(MAX_RECEIVE_LENGTH);
gw.begin();
// C++ classes and interrupts really sucks. Need to attach interrupt
// outside thw Gateway class due to language shortcomings! Gah!
if (gw.isLedMode()) {
// Add led timer interrupt
MsTimer2::set(300, ledTimersInterrupt);
MsTimer2::start();
// Add interrupt for inclustion button to pin
PCintPort::attachInterrupt(INCLUSION_MODE_PIN, startInclusionInterrupt, RISING);
}
}
void loop()
{
gw.processRadioMessage();
checkSerialInput();
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
Serial.print("H: ");
Serial.println(humidity);
Serial.print("T: ");
Serial.println(temperature);
if (humidity != lastHum) {
gw.sendVariable(CHILD_ID_HUM, V_HUM, humidity, 1);
lastHum = humidity;
}
if (temperature != lastTemp) {
gw.sendVariable(CHILD_ID_TEMP, V_TEMP, temperature, 1);
lastTemp = temperature;
}
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(1000); //delay to allow serial to fully print before sleep
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
}
void startInclusionInterrupt() {
gw.startInclusionInterrupt();
}
void ledTimersInterrupt() {
gw.ledTimersInterrupt();
}
void checkSerialInput() {
if (commandComplete) {
// A command wass issued from serial interface
// We will now try to send it to the actuator
commandComplete = false;
gw.parseAndSend(inputString);
// clear the string:
inputString = “”;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == ‘\n’) {
commandComplete = true;
} else {
// add it to the inputString:
inputString += inChar;
}
}
}
[/code]
The code loads onto the board without error… I had to comment out the the SENSOR gw(9,10) line as I didn’t know what to do there…
But the plugin doesn’t see the LIB version so I take it the code is wrong anyway…