• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Mysensors Domoticz 2 wezly do bramy MQTT
#1
Witam

Problem dotyczy Mysensors 2.3.2 i wspolpracy "MySensors Gateway with MQTT interface" z Domoticza. Posiadam dwa urzadzenia jedno oparte o W5100 drugie o ENC28J60, kazde obslugeje po 4 przekazniki, napisalem bardzo podobne softy i osobno kazde z urzadzen z gateway-em MQTT MySensors na Domo dziala poprawnie i stabilnie. Problem zaczyna sie gdy wlacze je jednoczesnie, gateway przyznaje obu node 0,  co zapewne dyskwalifikuje mozliwosc poprawnej pracy. Niestety sa ignorowane polecenia #define MY_MQTT_CLIENT_ID "1" lub 2, czy tez np #define MY_NODE_ID 3 lub 4 (dla drugiego urzadzenia). Wlaczenie dwoch bram (z tym samym lub chyba nawet roznymi brokerami mqtt) rowniez nie zapewnia stabilnej pracy, oczywiscie definiujac rozne tematy mqtt. Jak wymusic aby gateway przyznal jednemu urzadzeniu node 0 a drugiemu np 1 dla tego "MySensors Gateway with MQTT"?

program dla W5100

Kod:
// Enable debug prints to serial monitor
#define MY_DEBUG

// Enable gateway ethernet module type
#define MY_GATEWAY_W5100

// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,100,240
#define MY_IP_GATEWAY_ADDRESS 192,168,100,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0

// 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.
// #define MY_MAC_ADDRESS 0x57, 0x51, 0x65, 0x13, 0x56, 0x28

// MQTT broker ip address or url. Define one or the other.
// #define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
#define MY_CONTROLLER_IP_ADDRESS 192,168,100,241

// The MQTT broker port to to open
#define MY_PORT 1883

#define MY_GATEWAY_MQTT_CLIENT
// Set this node's subscribe and publish topic prefix
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "domoticz/in/MyMQTT"
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "domoticz/out/MyMQTT"

// Set MQTT client id
#define MY_MQTT_CLIENT_ID "1"
// #define MY_NODE_ID 3
// #define MY_PARENT_ID 2

// The port to keep open on node server mode / or port to contact in client mode
// #define MY_PORT 5505

#include <SPI.h>
#include <Ethernet.h>
#include <MySensors.h>


#define MY_REPEATER_FEATURE

#define RELAY_PIN 2  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 4 // Total number of attached relays
#define RELAY_ON 0  // GPIO value to write to turn on attached relay
#define RELAY_OFF 1 // GPIO value to write to turn off attached relay


void before()
{
  for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF);
  }
}

void setup() {

}

void presentation()
{
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Testy_Mirmila_na_UNO", "0.38");

  for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    present(sensor, S_BINARY);
  }
}

void loop() {

}

void receive(const MyMessage &message)
{
  // We only expect one type of message from controller. But we better check anyway.
  if (message.getType() == V_STATUS) {
    // Change relay state
    digitalWrite(message.getSensor() - 1 + RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
    // Store state in eeprom
    saveState(message.getSensor(), message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.getSensor());
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  }
}
program dla ENC28J60

Kod:
// Enable debug prints to serial monitor
#define MY_DEBUG


// Enable gateway ethernet module type
#define MY_GATEWAY_ENC28J60

// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,100,200
#define MY_IP_GATEWAY_ADDRESS 192,168,100,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0

// 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.
// #define MY_MAC_ADDRESS 0x52, 0x57, 0x68, 0x83, 0x46, 0x29

// The port to keep open on node server mode / or port to contact in client mode
// #define MY_PORT 5004

#define MY_GATEWAY_MQTT_CLIENT

// MQTT broker ip address or url. Define one or the other.
// #define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
#define MY_CONTROLLER_IP_ADDRESS 192,168,100,241

// The MQTT broker port to to open
#define MY_PORT 1883

// Set this node's subscribe and publish topic prefix
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "domoticz/in/MyMQTT/"
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "domoticz/out/MyMQTT/"

// Set MQTT client id
#define MY_MQTT_CLIENT_ID "2"
//#define MY_NODE_ID 5




#include <SPI.h>
#include <UIPEthernet.h>
#include <MySensors.h>
//#include <utility/logging.h>

#define MY_REPEATER_FEATURE

#define RELAY_PIN 4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 4 // Total number of attached relays
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay

void before()
{
  for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
    // Then set relay pins in output mode
    pinMode(pin, OUTPUT);
    // Set relay to last known state (using eeprom storage)
    digitalWrite(pin, loadState(sensor) ? RELAY_ON : RELAY_OFF);
  }
}

void setup() {

}

void presentation()
{
  // Send the sketch version information to the gateway and Controller
  sendSketchInfo("Testy_Mirmila_na_Arduino", "0.2");

  for (int sensor = 1, pin = RELAY_PIN; sensor <= NUMBER_OF_RELAYS; sensor++, pin++) {
    // Register all sensors to gw (they will be created as child devices)
    present(sensor, S_BINARY);
  }
}

void loop() {

}

void receive(const MyMessage &message)
{
  // We only expect one type of message from controller. But we better check anyway.
  if (message.getType() == V_STATUS) {
    // Change relay state
    digitalWrite(message.getSensor() - 1 + RELAY_PIN, message.getBool() ? RELAY_ON : RELAY_OFF);
    // Store state in eeprom
    saveState(message.getSensor(), message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.getSensor());
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  }
}
port szeregoey dla W5100, i problem taki, ze dla ENC28J60 wyglada to identycznie (oczywiscie zmienna jest tylko  ip)

Kod:
15:24:31.878 -> 0 MCO:BGN:INIT GW,CP=R-NGA---,FQ=16,REL=255,VER=2.3.2
15:24:31.878 -> 4 MCO:BGN:BFR
15:24:32.465 -> 566 GWT:TPC:IP=192.168.100.240
15:24:33.459 -> 1569 MCO:BGN:STP
15:24:33.459 -> 1570 MCO:REG:NOT NEEDED
15:24:33.459 -> 1572 MCO:BGN:INIT OK,TSP=NA
15:24:33.459 -> 1575 GWT:TPC:IP=192.168.100.240
15:24:34.490 -> 2579 GWT:RMQ:CONNECTING...
15:24:34.490 -> 2584 GWT:RMQ:OK
15:24:34.490 -> 2585 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/255/0/0/17,MSG SENT
15:24:34.490 -> 2592 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/255/3/0/11,MSG SENT
15:24:34.490 -> 2598 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/255/3/0/12,MSG SENT
15:24:34.490 -> 2605 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/1/0/0/3,MSG SENT
15:24:34.490 -> 2611 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/2/0/0/3,MSG SENT
15:24:34.490 -> 2617 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/3/0/0/3,MSG SENT
15:24:34.490 -> 2623 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/4/0/0/3,MSG SENT
15:24:36.318 -> 4422 GWT:IMQ:TOPIC=domoticz/out/MyMQTT/0/0/3/0/18, MSG RECEIVED
15:24:36.318 -> 4428 GWT:TPS:TOPIC=domoticz/in/MyMQTT/0/255/3/0/22,MSG SENT
15:24:43.013 -> 11131 GWT:IMQ:TOPIC=domoticz/out/MyMQTT/0/4/1/0/2, MSG RECEIVED
15:24:43.013 -> Incoming change for sensor:4, New status: 0
15:24:45.213 -> 13333 GWT:IMQ:TOPIC=domoticz/out/MyMQTT/0/2/1/0/2, MSG RECEIVED
15:24:45.260 -> Incoming change for sensor:2, New status: 0
15:24:49.560 -> 17676 GWT:IMQ:TOPIC=domoticz/out/MyMQTT/0/4/1/0/2, MSG RECEIVED
15:24:49.560 -> Incoming change for sensor:4, New status: 1
15:24:51.555 -> 19646 GWT:IMQ:TOPIC=domoticz/out/MyMQTT/0/2/1/0/2, MSG RECEIVED
15:24:51.555 -> Incoming change for sensor:2, New status: 1
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości