La gateway (passerelle) sert à transmettre les informations entre les nœuds (Capteur ou Actionneur) et le contrôleur Jeedom via un protocole radio 2,4Ghz.
L’intérêt de la passerelle Ethernet par rapport à la passerelle USB(série) est de pouvoir la déporté du contrôleur Jeedom.
Avantages :
- On s'affranchit alors de la limite d'utilisation d'un câble USB (5m)
- Libère un connecteur USB sur la machine Jeedom (pratique en virtualisation)
- La dépendance du plugin MySensors au module NodeJS serialport
[*]La passerelle MySensors Ethernet doit être alimenté en +5V et donc être raccordé en plus de l’Ethernet à une alimentation USB (ça peut être un Hub USB alimenté, ce qui permet de brancher également des nœuds MySensors).
Elle se compose d'un Arduino Nano, d'un module radio NRF24L01+, d'un module Ethernet W5100 (ou ENC28J60) et de 3 leds pour l’état de la communication.
Le module Ethernet W5100 gère lui même une partie de la communication Ethernet contrairement au module ENC2860, ce qui libère des ressources de traitement et de mémoire sur l'arduino.
La suite des explications portera sur une passerelle Ethernet avec module W5100.
La passerelle MySensors Ethernet étant raccordée au réseau IP, il faut lui définir et lui réserver une adresse IP fixe qui ne fait pas partie de la plage DHCP du routeur ou de la box internet.
Pour la suite, on considerera que l'adresse IP est 192.168.0.100. Elle est bien sûr à adapter à votre réseau.
Cette description est basé sur la page officielle "MySensors - Building Ethernet Gateway".
Composants :
- Arduino Nano
- NRF24L01+ Radio
- Module Ethernet W5100
- Un boitier
- Un câble USB avec alimentation (attention mini B, pas de micro comme pour les téléphones)
Le schéma de câblage est celui proposé par le site officiel MySensors.
Attention, certains modules Ethernet W5100 commercialisés fonctionnent en 5V et non en 3,3V comme indiqué sur le site MySensors.
Normalement, la tension de 5V (+5) est visible sur le module (Voir photos du module).
Connexion des modules :
Code : Tout sélectionner
Arduino NRF24L01 Ethernet module W5100 5V
GND-----GND-------------GND
3.3V----VCC
5V----------------------VCC
13----------------------SCK
12----------------------MISO/SO
11----------------------MOSI/SI
10----------------------SS/CS
A2------MISO
A1------MOSI
A0------SCK
6-------CSN
5-------CE
Code : Tout sélectionner
Led Arduino Pin Fonction
Rouge 7 Error/Err
Verte 8 Read/RX
Jaune 9 Transmit/TX
Si vous souhaitez mettre un bouton poussoir d'inclusion, il doit être entre la pin 3 de l'arduino et GND.
Sur les photos, on peut voir 2 condensateurs. Il y en a un sur le 3,3V et un sur le 5V. C'est par sécurité, mais ce n'est pas obligatoire.
Photos
Module Ethernet W5100
[img]MySensorsGatewayEthernet-W5100Composants.jpg[/img]
[img]MySensorsGatewayEthernet-W5100Soudures.jpg[/img]
Exemple d’intégration d'une boite Gateway MySensors Ethernet
[img]MySensorsGatewayEthernet-Boitier.jpg[/img]
[img]MySensorsGatewayEthernet-BoitierDessus.jpg[/img]
Programmation Arduino
- Utiliser l'IDE Arduino 1.5.8 (mini)
- Utiliser la librairie MySensors 1.4.1 (du 03/01/2015 dans mon cas).
- Modifier le fichier RF24_config.h dans (XXX/libraries/MySensors/utility) en supprimant // devant "#define SOFTSPI".
- Adapter l'adresse IP désirée dans le fichier EthernetGateway.ino.
- Televerser...
Code : Tout sélectionner
/*
* Copyright (C) 2013 Henrik Ekblad <henrik.ekblad@gmail.com>
*
* Contribution by a-lurker
*
* 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 EthernetGateway sends data received from sensors to the ethernet link.
* The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
*
* The GW code is designed for Arduino 328p / 16MHz. ATmega168 does not have enough memory to run this program.
*
*
* COMPILING WIZNET (W5100) ETHERNET MODULE
* > Edit RF24_config.h in (libraries\MySensors\utility) to enable softspi (remove // before "#define SOFTSPI").
*
* COMPILING ENC28J60 ETHERNET MODULE
* > Use Arduino IDE 1.5.7 (or later)
* > Disable DEBUG in Sensor.h before compiling this sketch. Othervise the sketch will probably not fit in program space when downloading.
* > Remove Ethernet.h include below and include UIPEthernet.h
* > Remove DigitalIO include
* Note that I had to disable UDP and DHCP support in uipethernet-conf.h to reduce space. (which means you have to choose a static IP for that module)
*
* VERA CONFIGURATION:
* Enter "ip-number:port" in the ip-field of the Arduino GW device. This will temporarily override any serial configuration for the Vera plugin.
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
*
* 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
*
* See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
*
*/
#include <DigitalIO.h> // This include can be removed when using UIPEthernet module
#include <SPI.h>
#include <MySensor.h>
#include <MyGateway.h>
#include <stdarg.h>
// Use this if you have attached a Ethernet ENC28J60 shields
//#include <UIPEthernet.h>
// Use this fo WizNET W5100 module and Arduino Ethernet Shield
#include <Ethernet.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
#define RADIO_CE_PIN 5 // radio chip enable
#define RADIO_SPI_SS_PIN 6 // radio SPI serial select
#define RADIO_ERROR_LED_PIN 7 // Error led pin
#define RADIO_RX_LED_PIN 8 // Receive led pin
#define RADIO_TX_LED_PIN 9 // the PCB, on board LED
#define IP_PORT 5003 // The port you want to open
IPAddress myIp (192, 168, 0, 100); // Configure your static ip-address here COMPILE ERROR HERE? Use Arduino IDE 1.5.7 or later!
// The MAC address can be anything you want but should be unique on your network.
// Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
// Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xE0 }; // DEAD BEEF FEED
// a R/W server on the port
EthernetServer server = EthernetServer(IP_PORT);
// No blink or button functionality. Use the vanilla constructor.
//MyGateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME);
// Uncomment this constructor if you have leds and include button attached to your gateway
MyGateway gw(RADIO_CE_PIN, RADIO_SPI_SS_PIN, INCLUSION_MODE_TIME, INCLUSION_MODE_PIN, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
int inputPos = 0;
void setup()
{
Ethernet.begin(mac, myIp);
// give the Ethernet interface a second to initialize
delay(1000);
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
gw.begin(RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, writeEthernet);
// start listening for clients
server.begin();
}
// This will be called when data should be written to ethernet
void writeEthernet(char *writeBuffer) {
server.write(writeBuffer);
}
void loop()
{
// if an incoming client connects, there will be
// bytes available to read via the client object
EthernetClient client = server.available();
if (client) {
// if got 1 or more bytes
if (client.available()) {
// read the bytes incoming from the client
char inChar = client.read();
if (inputPos<MAX_RECEIVE_LENGTH-1) {
// if newline then command is complete
if (inChar == '\n') {
// a command was issued by the client
// we will now try to send it to the actuator
inputString[inputPos] = 0;
// echo the string to the serial port
Serial.print(inputString);
gw.parseAndSend(inputString);
// clear the string:
inputPos = 0;
} else {
// add it to the inputString:
inputString[inputPos] = inChar;
inputPos++;
}
} else {
// Incoming message too long. Throw away
inputPos = 0;
}
}
}
gw.processRadioMessage();
}
Tests/Validation du montage
Pour tester, il suffit de lancer en ligne de commande :
ping 192.168.0.100
192.168.0.100 étant l'adresse IP paramétrée précédemment pour cette passerelle Ethernet.
- Si vous obtenez "Réponse de 192.168.0.100 : Impossible de joindre l'hôte de destination." : il y a un problème.
- Si vous obtenez "Réponse de 192.168.0.100 : octets=32 temps<1ms TTL=128" : vous pouvez passer au test suivant.
Démarrer un node MySensors, vous devez voir les trames s'afficher.
Exemple : 83;255;0;0;18;1.4 83;255;3;0;6;255 83;255;3;0;11;Relay
Recommandations
Il ne faut pas ouvrir le port correspondant à la passerelle ethernet dans la box du FAI (ou routeur) sauf si vous souhaitez laisser l’accès libre au monde entier à votre installation domotique MySensors...