GithubHelp home page GithubHelp logo

Comments (5)

jmbinette avatar jmbinette commented on August 19, 2024

@jezzaaa Di you find a way to solve this ?

I have exactly the same problem and running both in Docker

from smartthings-mqtt-bridge.

jezzaaa avatar jezzaaa commented on August 19, 2024

Yes, I hacked the DTH code to prefix the MAC with "MQTT", to make it more likely to be unique.

But I gave up on trying to use MQTT.

from smartthings-mqtt-bridge.

jmbinette avatar jmbinette commented on August 19, 2024

MQTT working for me, let me know if I can help

Could you point me the exact places you had to modify DTH?

I thought it was the way ST hub was communicating, not related to code :
"Yes, the SmartThings local incoming calls work by whitelisting by MAC address. And outgoing calls work by IP"

from smartthings-mqtt-bridge.

jezzaaa avatar jezzaaa commented on August 19, 2024

I can do most of what I want without MQTT, so there isn't an urgent need. But it'd be nice - when I get a bit of time.

My diff looks like the below:

<     // Setting Network Device Id
<     def hex = "$settings.mac".toUpperCase().replaceAll(':', '')
<     if (device.deviceNetworkId != "$hex") {
<         device.deviceNetworkId = "$hex"
<         log.debug "Device Network Id set to ${device.deviceNetworkId}"
---
>     def hex = ""
>     if (device.deviceNetworkId == NULL || device.deviceNetworkId == "") {
>         // Setting Network Device Id
>         //hex = "MQTT"+$settings.mac.toUpperCase().replaceAll(':', '')
>         hex = ipToHex(settings.ip+":"+settings.port)
>         log.debug "debug:"+hex
>         if (device.deviceNetworkId != "$hex") {
>             device.deviceNetworkId = "$hex"
>             log.debug "Device Network Id set to $hex -> ${device.deviceNetworkId}"
>         }

I originally just prefixed the right-hand-side of the assignment to hex with the string "MQTT". This is now commented out and replaced - not because it didn't work but because it didn't make sense to me to use the MAC address at all.

The MAC address is unique to the device, but not to the services running on the device. Instead, it makes sense to use something that's unique to the service (and doesn't have to be unique to the site because it will always operate in the local network).

So the new code gets the IP address and port number of the listening socket, converts them to hex and joints them together with a colon. In this way, a different service listening on a different port will have a different device ID even when it's running on the same device (thus same MAC).

The call to ipToHex() refers to a function I added, but didn't include in the above diff, for clarity. It looks like this:

// accepts a IP:PORT string and converts it to a hex identifier
// for setting the SmartThings deviceNetworkId
// NOTE: does not handle octet less than 0x10 = 16!
private String ipToHex(String ip) {
  def parts   = ip.tokenize(':')
  def address = parts[0]
  def port            = parts[1]
  def octets  = address.tokenize('.')
  def hex             = ""

  log.debug "converting ipToHex"
  octets.each {
    hex = hex + Integer.toHexString(it as Integer).toUpperCase()
  }
  hex = hex + ":" + Integer.toHexString(port as Integer).toUpperCase().padLeft(4,'0')
  return hex
}

from smartthings-mqtt-bridge.

jmbinette avatar jmbinette commented on August 19, 2024

Great ! Thank you I will def try that !

@stjohnjohnson could we integrate this kind of mod ? I think it would help many people

from smartthings-mqtt-bridge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.