Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
Untitled diff
作成日
11 年前
差分は期限切れになりません
クリア
エクスポート
共有
説明
68 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
217 行
すべてコピー
69 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
217 行
すべてコピー
/**
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
* network topology allowing messages to be routed to nodes.
*
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
*
* Documentation: http://www.mysensors.org
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
* Support Forum: http://forum.mysensors.org
*
*
* This program is free software; you can redistribute it and/or
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
* version 2 as published by the Free Software Foundation.
*
*
*******************************
*******************************
*
*
* REVISION HISTORY
* REVISION HISTORY
* Version 1.0 - Henrik EKblad
* Version 1.0 - Henrik EKblad
* Contribution by a-lurker and Anticimex,
* Contribution by a-lurker and Anticimex,
* Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
* Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
コピー
コピー済み
コピー
コピー済み
*
*
Contribution by Ivo Pullens (ESP8266 support)
*
*
* DESCRIPTION
* DESCRIPTION
コピー
コピー済み
コピー
コピー済み
* The EthernetGateway sends data received from sensors to the
ethernet
link.
* The EthernetGateway sends data received from sensors to the
WiFi
link.
* The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
* 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 MyConfig.h in (libraries\MySensors\) 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:
* 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.
* 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
* E.g. If you want to use the defualt values in this sketch enter: 192.168.178.66:5003
*
*
* LED purposes:
* LED purposes:
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
* - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - 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
* - 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
*
*
* See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
* See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
コピー
コピー済み
コピー
コピー済み
* The ESP8266 however requires different wiring:
* nRF24L01+ ESP8266
* VCC VCC
* CE GPIO4
* CSN/CS GPIO15
* SCK GPIO14
* MISO GPIO12
* MOSI GPIO13
*
* Not all ESP8266 modules have all pins available on their external interface.
* This code has been tested on an ESP-12 module.
* The ESP8266 requires a certain pin configuration to download code, and another one to run code:
* - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
* - Connect GPIO15 via 10K pulldown resistor to GND
* - Connect CH_PD via 10K resistor to VCC
* - Connect GPIO2 via 10K resistor to VCC
* - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
*
* Signing, RF69 radio, inclusion button and a separate SPI flash are not supported yet!
*
*
コピー
コピー済み
コピー
コピー済み
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
*/
*/
#define NO_PORTB_PINCHANGES
#define NO_PORTB_PINCHANGES
コピー
コピー済み
コピー
コピー済み
#include <DigitalIO.h> // This include can be removed when using UIPEthernet module
#include <SPI.h>
#include <SPI.h>
コピー
コピー済み
コピー
コピー済み
#include <MySigningNone.h>
#include <MyTransportRFM69.h>
#include <MyTransportNRF24.h>
#include <MyTransportNRF24.h>
コピー
コピー済み
コピー
コピー済み
#include <
MyHwATMega328
.h>
#include <
EEPROM
.h>
#include <
MySigningAtsha204Soft
.h>
#include <
MyHwESP8266
.h>
#include <
MySigningAtsha204
.h>
#include <
ESP8266WiFi
.h>
#include <MyParserSerial.h>
#include <MyParserSerial.h>
#include <MySensor.h>
#include <MySensor.h>
#include <stdarg.h>
#include <stdarg.h>
コピー
コピー済み
コピー
コピー済み
#include <PinChangeInt.h>
#include "GatewayUtil.h"
#include "GatewayUtil.h"
コピー
コピー済み
コピー
コピー済み
const char *ssid = "MySSID"; // cannot be longer than 32 characters!
// Use this if you have attached a Ethernet ENC28J60 shields
const char *pass = "MyVerySecretPassword"; //
// #include <UIPEthernet.h>
// Use this for 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_TIME 1 // Number of minutes inclusion mode is enabled
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
//
#define INCLUSION_MODE_PIN 3 // Digital pin used for inclusion mode button
コピー
コピー済み
コピー
コピー済み
#define RADIO_CE_PIN
5
// radio chip enable
#define RADIO_CE_PIN
4
// radio chip enable
#define RADIO_SPI_SS_PIN
6
// radio SPI serial select
#define RADIO_SPI_SS_PIN
15
// radio SPI serial select
#define RADIO_ERROR_LED_PIN 7 // Error led pin
#define RADIO_ERROR_LED_PIN 7 // Error led pin
#define RADIO_RX_LED_PIN 8 // Receive led pin
#define RADIO_RX_LED_PIN 8 // Receive led pin
#define RADIO_TX_LED_PIN 9 // the PCB, on board LED
#define RADIO_TX_LED_PIN 9 // the PCB, on board LED
// NRFRF24L01 radio driver (set low transmit power by default)
// NRFRF24L01 radio driver (set low transmit power by default)
MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);
MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW);
コピー
コピー済み
コピー
コピー済み
//MyTransportRFM69 transport;
// Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
//MySigningNone signer;
//MySigningAtsha204Soft signer;
//MySigningAtsha204 signer;
// Hardware profile
// Hardware profile
コピー
コピー済み
コピー
コピー済み
MyHwATMega328
hw;
MyHwESP8266
hw;
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
// Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h)
// To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
// To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h
#ifdef WITH_LEDS_BLINKING
#ifdef WITH_LEDS_BLINKING
MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN);
#else
#else
MySensor gw(transport, hw /*, signer*/);
MySensor gw(transport, hw /*, signer*/);
#endif
#endif
#define IP_PORT 5003 // The port you want to open
#define IP_PORT 5003 // The port you want to open
コピー
コピー済み
コピー
コピー済み
IPAddress myIp (192, 168, 178, 66); // 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, 0xED }; // DEAD BEEF FEED
// a R/W server on the port
// a R/W server on the port
コピー
コピー済み
コピー
コピー済み
EthernetServer
server
= EthernetServer
(IP_PORT);
WiFiServer
server
(IP_PORT);
// handle to open connection
// handle to open connection
コピー
コピー済み
コピー
コピー済み
EthernetClient
client
= EthernetClient()
;
WiFiClient
client
;
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface
int inputPos = 0;
int inputPos = 0;
bool sentReady = false;
bool sentReady = false;
void output(const char *fmt, ... ) {
void output(const char *fmt, ... ) {
va_list args;
va_list args;
va_start (args, fmt );
va_start (args, fmt );
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
va_end (args);
va_end (args);
Serial.print(serialBuffer);
Serial.print(serialBuffer);
server.write(serialBuffer);
server.write(serialBuffer);
}
}
void setup()
void setup()
{
{
コピー
コピー済み
コピー
コピー済み
Ethernet
.begin(
mac, myIp);
// Setup console
Serial
.begin(
115200);
Serial.println();
Serial.println("ESP8266 MySensors Gateway");
Serial.print("Connecting to "); Serial.println(ssid);
コピー
コピー済み
コピー
コピー済み
(void)WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected!");
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.flush();
#ifndef INCLUSION_MODE_PIN
setupGateway(255, INCLUSION_MODE_TIME, output);
#else
setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output);
// Add interrupt for inclusion button to pin
// Add interrupt for inclusion button to pin
PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING);
コピー
コピー済み
コピー
コピー済み
#endif
// give the Ethernet interface a second to initialize
delay(1000);
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
// Initialize gateway at maximum PA level, channel 70 and callback for write operations
gw.begin(incomingMessage, 0, true, 0);
gw.begin(incomingMessage, 0, true, 0);
コピー
コピー済み
コピー
コピー済み
// start listening for clients
// start listening for clients
server.begin();
server.begin();
コピー
コピー済み
コピー
コピー済み
}
}
void loop() {
void loop() {
gw.process();
gw.process();
コピー
コピー済み
コピー
コピー済み
#ifdef INCLUSION_MODE_PIN
checkButtonTriggeredInclusion();
checkButtonTriggeredInclusion();
checkInclusionFinished();
checkInclusionFinished();
コピー
コピー済み
コピー
コピー済み
#endif
コピー
コピー済み
コピー
コピー済み
//
if
an incoming client connects, there will be
//
check
if
there are any new clients
// bytes available to read via the
client
object
if (server.hasClient())
EthernetClient new
client = server.available();
{
// if a new client connects make sure to dispose any previous existing sockets
if (
client
)
if (newclient) {
{
if (client != newclient) {
client.stop();
client.stop();
}
client = newclient;
client = server.available();
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY);
}
}
}
if (client) {
if (client) {
if (!client.connected()) {
if (!client.connected()) {
client.stop();
client.stop();
} else if (client.available()) {
} else if (client.available()) {
// read the bytes incoming from the client
// read the bytes incoming from the client
char inChar = client.read();
char inChar = client.read();
if (inputPos<MAX_RECEIVE_LENGTH-1) {
if (inputPos<MAX_RECEIVE_LENGTH-1) {
// if newline then command is complete
// if newline then command is complete
if (inChar == '\n') {
if (inChar == '\n') {
Serial.println("Finished");
Serial.println("Finished");
// a command was issued by the client
// a command was issued by the client
// we will now try to send it to the actuator
// we will now try to send it to the actuator
inputString[inputPos] = 0;
inputString[inputPos] = 0;
// echo the string to the serial port
// echo the string to the serial port
Serial.print(inputString);
Serial.print(inputString);
parseAndSend(gw, inputString);
parseAndSend(gw, inputString);
// clear the string:
// clear the string:
inputPos = 0;
inputPos = 0;
} else {
} else {
// add it to the inputString:
// add it to the inputString:
inputString[inputPos] = inChar;
inputString[inputPos] = inChar;
inputPos++;
inputPos++;
}
}
} else {
} else {
// Incoming message too long. Throw away
// Incoming message too long. Throw away
inputPos = 0;
inputPos = 0;
}
}
}
}
}
}
}
}
保存された差分
原文
ファイルを開く
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik EKblad * Contribution by a-lurker and Anticimex, * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de> * * * 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 MyConfig.h in (libraries\MySensors\) 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: * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h * - 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. * */ #define NO_PORTB_PINCHANGES #include <DigitalIO.h> // This include can be removed when using UIPEthernet module #include <SPI.h> #include <MySigningNone.h> #include <MyTransportRFM69.h> #include <MyTransportNRF24.h> #include <MyHwATMega328.h> #include <MySigningAtsha204Soft.h> #include <MySigningAtsha204.h> #include <MyParserSerial.h> #include <MySensor.h> #include <stdarg.h> #include <PinChangeInt.h> #include "GatewayUtil.h" // Use this if you have attached a Ethernet ENC28J60 shields // #include <UIPEthernet.h> // Use this for 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 // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW); //MyTransportRFM69 transport; // Message signing driver (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) //MySigningNone signer; //MySigningAtsha204Soft signer; //MySigningAtsha204 signer; // Hardware profile MyHwATMega328 hw; // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h #ifdef WITH_LEDS_BLINKING MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN); #else MySensor gw(transport, hw /*, signer*/); #endif #define IP_PORT 5003 // The port you want to open IPAddress myIp (192, 168, 178, 66); // 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, 0xED }; // DEAD BEEF FEED // a R/W server on the port EthernetServer server = EthernetServer(IP_PORT); // handle to open connection EthernetClient client = EthernetClient(); char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; bool sentReady = false; void output(const char *fmt, ... ) { va_list args; va_start (args, fmt ); vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args); va_end (args); Serial.print(serialBuffer); server.write(serialBuffer); } void setup() { Ethernet.begin(mac, myIp); setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output); // Add interrupt for inclusion button to pin PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING); // 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(incomingMessage, 0, true, 0); // start listening for clients server.begin(); } void loop() { gw.process(); checkButtonTriggeredInclusion(); checkInclusionFinished(); // if an incoming client connects, there will be // bytes available to read via the client object EthernetClient newclient = server.available(); // if a new client connects make sure to dispose any previous existing sockets if (newclient) { if (client != newclient) { client.stop(); client = newclient; output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY); } } if (client) { if (!client.connected()) { client.stop(); } else 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') { Serial.println("Finished"); // 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); parseAndSend(gw, 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; } } } }
変更されたテキスト
ファイルを開く
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik EKblad * Contribution by a-lurker and Anticimex, * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de> * Contribution by Ivo Pullens (ESP8266 support) * * DESCRIPTION * The EthernetGateway sends data received from sensors to the WiFi link. * The gateway also accepts input on ethernet interface, which is then sent out to the radio network. * * 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: * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h * - 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. * The ESP8266 however requires different wiring: * nRF24L01+ ESP8266 * VCC VCC * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch') * - Connect GPIO15 via 10K pulldown resistor to GND * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') * * Signing, RF69 radio, inclusion button and a separate SPI flash are not supported yet! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. */ #define NO_PORTB_PINCHANGES #include <SPI.h> #include <MyTransportNRF24.h> #include <EEPROM.h> #include <MyHwESP8266.h> #include <ESP8266WiFi.h> #include <MyParserSerial.h> #include <MySensor.h> #include <stdarg.h> #include "GatewayUtil.h" const char *ssid = "MySSID"; // cannot be longer than 32 characters! const char *pass = "MyVerySecretPassword"; // #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 4 // radio chip enable #define RADIO_SPI_SS_PIN 15 // 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 // NRFRF24L01 radio driver (set low transmit power by default) MyTransportNRF24 transport(RADIO_CE_PIN, RADIO_SPI_SS_PIN, RF24_PA_LEVEL_GW); // Hardware profile MyHwESP8266 hw; // Construct MySensors library (signer needed if MY_SIGNING_FEATURE is turned on in MyConfig.h) // To use LEDs blinking, uncomment WITH_LEDS_BLINKING in MyConfig.h #ifdef WITH_LEDS_BLINKING MySensor gw(transport, hw /*, signer*/, RADIO_RX_LED_PIN, RADIO_TX_LED_PIN, RADIO_ERROR_LED_PIN); #else MySensor gw(transport, hw /*, signer*/); #endif #define IP_PORT 5003 // The port you want to open // a R/W server on the port WiFiServer server(IP_PORT); // handle to open connection WiFiClient client; char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; bool sentReady = false; void output(const char *fmt, ... ) { va_list args; va_start (args, fmt ); vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args); va_end (args); Serial.print(serialBuffer); server.write(serialBuffer); } void setup() { // Setup console Serial.begin(115200); Serial.println(); Serial.println("ESP8266 MySensors Gateway"); Serial.print("Connecting to "); Serial.println(ssid); (void)WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("Connected!"); Serial.print("IP: "); Serial.println(WiFi.localIP()); Serial.flush(); #ifndef INCLUSION_MODE_PIN setupGateway(255, INCLUSION_MODE_TIME, output); #else setupGateway(INCLUSION_MODE_PIN, INCLUSION_MODE_TIME, output); // Add interrupt for inclusion button to pin PCintPort::attachInterrupt(pinInclusion, startInclusionInterrupt, RISING); #endif // Initialize gateway at maximum PA level, channel 70 and callback for write operations gw.begin(incomingMessage, 0, true, 0); // start listening for clients server.begin(); } void loop() { gw.process(); #ifdef INCLUSION_MODE_PIN checkButtonTriggeredInclusion(); checkInclusionFinished(); #endif //check if there are any new clients if (server.hasClient()) { if (client) { client.stop(); } client = server.available(); output(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY); } if (client) { if (!client.connected()) { client.stop(); } else 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') { Serial.println("Finished"); // 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); parseAndSend(gw, 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; } } } }
違いを見つける