Skip to content

Commit 3246799

Browse files
committed
Initial commit of "legacy" examples/libraries
0 parents  commit 3246799

File tree

863 files changed

+144384
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

863 files changed

+144384
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MySensorsArduinoExamples
2+
=======
3+
4+
This repository includes the Examples, which where included in MySensors 1.x releases, that depends on external libraries.
5+
6+
As the libraries that is needed for these examples are not maintained by, or distributed with MySensors, they have been moved to their own repository.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
* DESCRIPTION
22+
*
23+
* Simple binary switch example
24+
* Connect button or door/window reed switch between
25+
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
26+
* http://www.mysensors.org/build/binary
27+
*/
28+
29+
30+
// Enable debug prints to serial monitor
31+
#define MY_DEBUG
32+
33+
// Enable and select radio type attached
34+
#define MY_RADIO_NRF24
35+
//#define MY_RADIO_RFM69
36+
37+
#include <SPI.h>
38+
#include <MySensors.h>
39+
#include <Bounce2.h>
40+
41+
#define CHILD_ID 3
42+
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
43+
44+
Bounce debouncer = Bounce();
45+
int oldValue=-1;
46+
47+
// Change to V_LIGHT if you use S_LIGHT in presentation below
48+
MyMessage msg(CHILD_ID,V_TRIPPED);
49+
50+
void setup()
51+
{
52+
// Setup the button
53+
pinMode(BUTTON_PIN,INPUT);
54+
// Activate internal pull-up
55+
digitalWrite(BUTTON_PIN,HIGH);
56+
57+
// After setting up the button, setup debouncer
58+
debouncer.attach(BUTTON_PIN);
59+
debouncer.interval(5);
60+
61+
}
62+
63+
void presentation() {
64+
// Register binary input sensor to gw (they will be created as child devices)
65+
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
66+
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
67+
present(CHILD_ID, S_DOOR);
68+
}
69+
70+
71+
// Check if digital input has changed and send in new value
72+
void loop()
73+
{
74+
debouncer.update();
75+
// Get the update value
76+
int value = debouncer.read();
77+
78+
if (value != oldValue) {
79+
// Send in the new value
80+
send(msg.set(value==HIGH ? 1 : 0));
81+
oldValue = value;
82+
}
83+
}
84+
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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-2016 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+
* DESCRIPTION
22+
*
23+
* Simple binary switch example
24+
* Connect button or door/window reed switch between
25+
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
26+
* A NeoPixel LED will be used to provide visual feedback of the sensor status.
27+
* http://www.mysensors.org/build/binary
28+
*/
29+
30+
31+
// Enable debug prints to serial monitor
32+
#define MY_DEBUG
33+
34+
// Enable and select radio type attached
35+
#define MY_RADIO_NRF24
36+
//#define MY_RADIO_RFM69
37+
38+
#include <Adafruit_NeoPixel.h>
39+
#include <MsTimer2.h>
40+
#include <SPI.h>
41+
#include <MySensors.h>
42+
#include <Bounce2.h>
43+
44+
#define LED_CYCLE_MS 30 // Update rate of LEDs, in [ms].
45+
#define NEO_PIN 6 // NeoPixels input pin
46+
#define CHILD_ID 3
47+
#define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch
48+
49+
Bounce debouncer = Bounce();
50+
int oldValue=-1;
51+
52+
static Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, NEO_PIN, NEO_GRB + NEO_KHZ800);
53+
54+
// Change to V_LIGHT if you use S_LIGHT in presentation below
55+
MyMessage msg(CHILD_ID,V_TRIPPED);
56+
57+
#define BLINK_TIMES(x) ((x)<<4)
58+
59+
static uint8_t ledR = 0;
60+
static uint8_t ledG = 0;
61+
static uint8_t ledB = 0;
62+
63+
void updateLed(void)
64+
{
65+
// Update the pattern (setting leds).
66+
if (ledR > 0) --ledR;
67+
if (ledG > 0) --ledG;
68+
if (ledB > 0) --ledB;
69+
// Determine of each color if it should be on or off.
70+
uint8_t r = ((ledR & 0x0F) < 6) ? 0 : 255;
71+
uint8_t g = ((ledG & 0x0F) < 6) ? 0 : 255;
72+
uint8_t b = ((ledB & 0x0F) < 6) ? 0 : 255;
73+
pixels.setPixelColor(0, r, g, b);
74+
pixels.show();
75+
}
76+
77+
void before()
78+
{
79+
// Initialize the NeoPixel chain
80+
pixels.begin();
81+
pixels.show();
82+
83+
// Configure timer interrupt
84+
MsTimer2::set(LED_CYCLE_MS, updateLed);
85+
MsTimer2::start();
86+
}
87+
88+
void setup()
89+
{
90+
// Setup the button
91+
pinMode(BUTTON_PIN,INPUT);
92+
// Activate internal pull-up
93+
digitalWrite(BUTTON_PIN,HIGH);
94+
95+
// After setting up the button, setup debouncer
96+
debouncer.attach(BUTTON_PIN);
97+
debouncer.interval(5);
98+
}
99+
100+
void presentation() {
101+
// Register binary input sensor to gw (they will be created as child devices)
102+
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
103+
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
104+
present(CHILD_ID, S_DOOR);
105+
}
106+
107+
void indication( const indication_t ind )
108+
{
109+
if ((INDICATION_TX == ind) || (INDICATION_GW_TX == ind))
110+
{
111+
// Blink Blue 1x
112+
ledB = BLINK_TIMES(1);
113+
Serial.println(F("TX"));
114+
} else if ((INDICATION_RX == ind) || (INDICATION_GW_RX == ind))
115+
{
116+
// Blink Blue 1x
117+
ledB = BLINK_TIMES(1);
118+
Serial.println(F("RX"));
119+
} else if (INDICATION_FIND_PARENT == ind)
120+
{
121+
// Blink Green 5x
122+
ledG = BLINK_TIMES(5);
123+
Serial.println(F("JOIN"));
124+
} else if (INDICATION_GOT_PARENT == ind)
125+
{
126+
// Green off
127+
ledG = BLINK_TIMES(0);
128+
Serial.println(F("JOINED"));
129+
} else if (ind > INDICATION_ERR_START)
130+
{
131+
// Blink Red, depending on the error number
132+
ledR = BLINK_TIMES(ind - INDICATION_ERR_START);
133+
Serial.print(F("ERROR")); Serial.println(ind - INDICATION_ERR_START);
134+
}
135+
}
136+
137+
// Check if digital input has changed and send in new value
138+
void loop()
139+
{
140+
debouncer.update();
141+
// Get the update value
142+
int value = debouncer.read();
143+
144+
if (value != oldValue) {
145+
// Send in the new value
146+
send(msg.set(value==HIGH ? 1 : 0));
147+
oldValue = value;
148+
}
149+
}
150+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
* DESCRIPTION
22+
*
23+
* Example sketch showing how to send in DS1820B OneWire temperature readings back to the controller
24+
* http://www.mysensors.org/build/temp
25+
*/
26+
27+
28+
// Enable debug prints to serial monitor
29+
//#define MY_DEBUG
30+
31+
// Enable and select radio type attached
32+
#define MY_RADIO_NRF24
33+
//#define MY_RADIO_RFM69
34+
35+
#include <SPI.h>
36+
#include <MySensors.h>
37+
#include <DallasTemperature.h>
38+
#include <OneWire.h>
39+
40+
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
41+
42+
#define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected
43+
#define MAX_ATTACHED_DS18B20 16
44+
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
45+
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
46+
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
47+
float lastTemperature[MAX_ATTACHED_DS18B20];
48+
int numSensors=0;
49+
boolean receivedConfig = false;
50+
boolean metric = true;
51+
// Initialize temperature message
52+
MyMessage msg(0,V_TEMP);
53+
54+
void setup()
55+
{
56+
// Startup up the OneWire library
57+
sensors.begin();
58+
// requestTemperatures() will not block current thread
59+
sensors.setWaitForConversion(false);
60+
}
61+
62+
void presentation() {
63+
// Send the sketch version information to the gateway and Controller
64+
sendSketchInfo("Temperature Sensor", "1.1");
65+
66+
// Fetch the number of attached temperature sensors
67+
numSensors = sensors.getDeviceCount();
68+
69+
// Present all sensors to controller
70+
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
71+
present(i, S_TEMP);
72+
}
73+
}
74+
75+
void loop()
76+
{
77+
// Fetch temperatures from Dallas sensors
78+
sensors.requestTemperatures();
79+
80+
// query conversion time and sleep until conversion completed
81+
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
82+
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
83+
sleep(conversionTime);
84+
85+
// Read temperatures and send them to controller
86+
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
87+
88+
// Fetch and round temperature to one decimal
89+
float temperature = static_cast<float>(static_cast<int>((getConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
90+
91+
// Only send data if temperature has changed and no error
92+
#if COMPARE_TEMP == 1
93+
if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
94+
#else
95+
if (temperature != -127.00 && temperature != 85.00) {
96+
#endif
97+
98+
// Send in the new temperature
99+
send(msg.setSensor(i).set(temperature,1));
100+
// Save new temperatures for next compare
101+
lastTemperature[i]=temperature;
102+
}
103+
}
104+
sleep(SLEEP_TIME);
105+
}

0 commit comments

Comments
 (0)