Connecting sensors directly to the Arduino gateway

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
      */

#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…

Probably need to see how @Jackpot is making out - refer here:
http://forum.micasaverde.com/index.php/topic,16170.msg130180.html#msg130180
It seems likely that sensor.cpp/h would need to be rehashed to eliminate the actual radio code, so it acts as a virtual radio instead.

You cannot use send commands from gateway. The radio cannot send to itself.

Instead you must do serial prints to the attached vera (simulating the normal received message-prints). Look at the (private) serial method in Gateway.cpp. You should probably make the gateway send the presentation string when inclusion mode has been triggered (and not the gateway starts up).

To do a presentation of the DHT sensor (as child 0); do:

Serial.print("0;0;");
Serial.print(M_PRESENTATION);
Serial.print(";");
Serial.print(S_HUM) ;
Serial.print(";");
Serial.println(LIBRARY_VERSION) ;

And to send a new humidity reading do:

Serial.print("0;0;");
Serial.print(M_SET_VARIABLE);
Serial.print(";");
Serial.print(V_HUM) ;
Serial.print(";");
Serial.println(<your new humidity value>) ;
Probably need to see how @Jackpot is making out - refer here:

Yeah I played with this for awhile and used something similar to what @hek suggested. Got it working but decided to abandon it. There could be timing issues and memory problems. Being that Arduino’s and Radio’s are so cheap it seemed pointless to pursue this at least for me.

[quote=“jackpot, post:4, topic:178446”]

Probably need to see how @Jackpot is making out - refer here:

Yeah I played with this for awhile and used something similar to what @hek suggested. Got it working but decided to abandon it. There could be timing issues and memory problems. Being that Arduino’s and Radio’s are so cheap it seemed pointless to pursue this at least for me.[/quote]

For the sake of learning… I will continue with my quest… but I agree. . the price doesn’t make it a long term feasible option… I think its more that it’s xmas and I cant get anything till the shops reopen… :stuck_out_tongue:

I will try the suggestions above and see if I can make sense of it all

Thanks

[quote=“jackpot, post:4, topic:178446”]

Probably need to see how @Jackpot is making out - refer here:

Yeah I played with this for awhile and used something similar to what @hek suggested. Got it working but decided to abandon it. There could be timing issues and memory problems. Being that Arduino’s and Radio’s are so cheap it seemed pointless to pursue this at least for me.[/quote]

you dont still have the code that worked for you?
I am getting nowhere with this as I dont understand it so clearly…

you dont still have the code that worked for you? I am getting nowhere with this as I dont understand it so clearly..

Sorry but I don’t have the code anymore. I did this back when using “gateway46” version of the Arduino App. I doubt if it would work with the latest version even if I had it still. You could use the example that @hek posted.

[quote=“jackpot, post:7, topic:178446”]

you dont still have the code that worked for you?
I am getting nowhere with this as I dont understand it so clearly…

Sorry but I don’t have the code anymore. I did this back when using “gateway46” version of the Arduino App. I doubt if it would work with the latest version even if I had it still. You could use the example that @hek posted.[/quote]

no worries… thanks.

I will try to start over… and try again

please, help to send the presentation string when inclusion mode has been triggered.
can’t get it working by myself