|
| 1 | +/** |
| 2 | + * The MySensors Arduino library handles the wireless radio link and protocol |
| 3 | + * between your home built sensors/actuators and HA controller of choice. |
| 4 | + * The sensors forms a self healing radio network with optional repeaters. Each |
| 5 | + * repeater and gateway builds a routing tables in EEPROM which keeps track of the |
| 6 | + * network topology allowing messages to be routed to nodes. |
| 7 | + * |
| 8 | + * Created by Henrik Ekblad <[email protected]> |
| 9 | + * Copyright (C) 2013-2015 Sensnology AB |
| 10 | + * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors |
| 11 | + * |
| 12 | + * Documentation: http://www.mysensors.org |
| 13 | + * Support Forum: http://forum.mysensors.org |
| 14 | + * |
| 15 | + * This program is free software; you can redistribute it and/or |
| 16 | + * modify it under the terms of the GNU General Public License |
| 17 | + * version 2 as published by the Free Software Foundation. |
| 18 | + * |
| 19 | + ******************************* |
| 20 | + * |
| 21 | + * REVISION HISTORY |
| 22 | + * WARNING: I use MySensors V1.6.0 (dev branch) (https://github.com/mysensors/Arduino/tree/development/libraries) |
| 23 | + * |
| 24 | + * Version 1.0 - Hubert Mickael <[email protected]> (https://github.com/Mickaelh51) |
| 25 | + * - Clean ino code |
| 26 | + * - Add MY_DEBUG mode in library |
| 27 | + * Version 0.2 (Beta 2) - Hubert Mickael <[email protected]> (https://github.com/Mickaelh51) |
| 28 | + * - Auto detect Oregon 433Mhz |
| 29 | + * - Add battery level |
| 30 | + * - etc ... |
| 31 | + * Version 0.1 (Beta 1) - Hubert Mickael <[email protected]> (https://github.com/Mickaelh51) |
| 32 | + * |
| 33 | + ******************************* |
| 34 | + * DESCRIPTION |
| 35 | + * This sketch provides an example how to implement a humidity/temperature from Oregon sensor. |
| 36 | + * - Oregon sensor's battery level |
| 37 | + * - Oregon sensor's id |
| 38 | + * - Oregon sensor's type |
| 39 | + * - Oregon sensor's channel |
| 40 | + * - Oregon sensor's temperature |
| 41 | + * - Oregon sensor's humidity |
| 42 | + * |
| 43 | + * MySensors gateway <=======> Arduino UNO <-- (PIN 2) --> 433Mhz receiver <=============> Oregon sensors |
| 44 | + */ |
| 45 | + |
| 46 | +// Enable debug prints |
| 47 | +#define MY_DEBUG |
| 48 | + |
| 49 | +#define MY_NODE_ID 10 |
| 50 | + |
| 51 | +// Enable and select radio type attached |
| 52 | +#define MY_RADIO_NRF24 |
| 53 | +//#define MY_RADIO_RFM69 |
| 54 | + |
| 55 | +#include <SPI.h> |
| 56 | +#include <MySensor.h> |
| 57 | +#include <Oregon.h> |
| 58 | + |
| 59 | +//Define pin where is 433Mhz receiver (here, pin 2) |
| 60 | +#define MHZ_RECEIVER_PIN 2 |
| 61 | +//Define maximum Oregon sensors (here, 3 differents sensors) |
| 62 | +#define COUNT_OREGON_SENSORS 3 |
| 63 | + |
| 64 | +#define CHILD_ID_HUM 0 |
| 65 | +#define CHILD_ID_TEMP 1 |
| 66 | +#define CHILD_ID_BAT 2 |
| 67 | + |
| 68 | +MyMessage msgHum(CHILD_ID_HUM, V_HUM); |
| 69 | +MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); |
| 70 | +MyMessage msgBat(CHILD_ID_BAT, V_VAR1); |
| 71 | + |
| 72 | +void setup () |
| 73 | +{ |
| 74 | + |
| 75 | + Serial.println("Setup started"); |
| 76 | + |
| 77 | + //Setup received data |
| 78 | + attachInterrupt(digitalPinToInterrupt(MHZ_RECEIVER_PIN), ext_int_1, CHANGE); |
| 79 | + |
| 80 | + Serial.println("Setup completed"); |
| 81 | +} |
| 82 | + |
| 83 | +void presentation() |
| 84 | +{ |
| 85 | + // Send the Sketch Version Information to the Gateway |
| 86 | + sendSketchInfo("Oregon Sensor", "1.0"); |
| 87 | + |
| 88 | + // Present all sensors to controller |
| 89 | + for (int i=0; i<COUNT_OREGON_SENSORS; i++) { |
| 90 | + present(i, S_TEMP); |
| 91 | + present(i, S_HUM); |
| 92 | + present(i, S_CUSTOM); //battery level |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +void loop () { |
| 99 | + //------------------------------------------ |
| 100 | + //Start process new data from Oregon sensors |
| 101 | + //------------------------------------------ |
| 102 | + cli(); |
| 103 | + word p = pulse; |
| 104 | + pulse = 0; |
| 105 | + sei(); |
| 106 | + if (p != 0) |
| 107 | + { |
| 108 | + if (orscV2.nextPulse(p)) |
| 109 | + { |
| 110 | + //Decode Hex Data once |
| 111 | + const byte* DataDecoded = DataToDecoder(orscV2); |
| 112 | + //Find or save Oregon sensors's ID |
| 113 | + int SensorID = FindSensor(id(DataDecoded),COUNT_OREGON_SENSORS); |
| 114 | + |
| 115 | + // just for DEBUG |
| 116 | + OregonType(DataDecoded); |
| 117 | + channel(DataDecoded); |
| 118 | + |
| 119 | + //Send messages to MySenors Gateway |
| 120 | + send(msgTemp.setSensor(SensorID).set(temperature(DataDecoded), 1)); |
| 121 | + send(msgHum.setSensor(SensorID).set(humidity(DataDecoded), 1)); |
| 122 | + send(msgBat.setSensor(SensorID).set(battery(DataDecoded), 1)); |
| 123 | + } |
| 124 | + |
| 125 | + } |
| 126 | +} |
0 commit comments