Giter VIP home page Giter VIP logo

Comments (7)

philips77 avatar philips77 commented on September 2, 2024

Did you create LightCTLClientDelegate object and registered it to a local Element in the app?

The model delegate has to bind a message ID with a type.
Have a look at the example:

init() {
let types: [StaticMeshMessage.Type] = [
GenericOnOffStatus.self
]
messageTypes = types.toMap()
}

where the GenericOnOffClientDelegate registers the status message.

from ios-nrf-mesh-library.

philips77 avatar philips77 commented on September 2, 2024

The delegate is added to local element here:

Model(sigModelId: .genericOnOffClientModelId, delegate: GenericOnOffClientDelegate()),

from ios-nrf-mesh-library.

philips77 avatar philips77 commented on September 2, 2024

You will find more info here: https://nordicsemiconductor.github.io/IOS-nRF-Mesh-Library/documentation/nordicmesh/localnode

from ios-nrf-mesh-library.

Ahmadshoh avatar Ahmadshoh commented on September 2, 2024

Yes. I did all these steps. Here are some codes from my project.

extension QBleMesh {
  func createNewMeshNetwork() {
    let provisioner = Provisioner.init(name: UIDevice.current.name)
    _ = meshNetworkManager.createNewMeshNetwork(withName: "bt-control", by: provisioner)
    _ = meshNetworkManager.save()
    
    meshNetworkDidChange()
  }
  
  func meshNetworkDidChange() {
    let meshNetwork = meshNetworkManager.meshNetwork!
    let primary: Element = Element(name: "PrimaryElement", location: .first, models: [
      Model(sigModelId: .genericOnOffClient, delegate: GenericOnOffClientDelegate(meshNetworkManager, statusManager: self)),
      Model(sigModelId: .lightCTLClient, delegate: LightCTLClientDelegate(meshNetworkManager, statusManager: self)),
      Model(sigModelId: .genericBatteryClient, delegate: GenericBatteryClientDelegate(meshNetwork, statusManager: self)),
//      Model(vendorModelId: .healthModelId, companyId: .companyId, delegate: VendorHealthClientDelegate(meshNetworkManager))
      Model(vendorModelId: .timerModelId, companyId: .companyId, delegate: VendorCountdownClientDelegate(meshNetworkManager))
    ])
    
    meshNetworkManager.localElements = [primary]
    
    setApplicationKey()
    setupModelApplicationKeysForLocalNode(meshNetwork.applicationKeys.first!)

    print("meshNetwork.nodes \(meshNetwork.nodes)")
    print("meshNetwork.groups \(meshNetwork.groups)")
    
    connection = NetworkConnection(to: meshNetwork)
    connection?.isConnectionModeAutomatic = true
    connection?.dataDelegate = meshNetworkManager
    connection?.logger = self
    meshNetworkManager.transmitter = connection
    connection?.open()
    
    provisioningService = ProvisioningService(meshNetworkManager: meshNetworkManager)
    meshNetworkManager.delegate = self
  }
  }
  

And here is LightCTLClientDelegate class

import Foundation
import nRFMeshProvision

class LightCTLClientDelegate: ModelDelegate {
  
  let meshNetworkManager: MeshNetworkManager
  let statusManager: StatusUpdate
  let messageTypes: [UInt32 : MeshMessage.Type]
  let isSubscriptionSupported: Bool = true
  
  var publicationMessageComposer: MessageComposer? {
    func compose() -> MeshMessage {
      return LightCTLSetUnacknowledged(lightness: UInt16(((Double(self.state) / 100.0) * 65535).rounded()), temperature: 10400, deltaUV: 0)
    }
    let request = compose()
    return {
      return request
    }
  }
  
  /// The current state of the Light CTL Client model.
  var state = 25 {
    didSet {
      publish(using: self.meshNetworkManager)
    }
  }
  
  init(_ meshNetworkManager: MeshNetworkManager, statusManager: StatusUpdate) {
    let types: [GenericMessage.Type] = [
      LightCTLStatus.self
    ]
    messageTypes = types.toMap()
    self.meshNetworkManager = meshNetworkManager
    self.statusManager = statusManager
  }
  
  // MARK: - Message handlers
  
  func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
             from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
    fatalError("Not possible")
  }
  
  func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,from source: Address, sentTo destination: MeshAddress) {
    if let status = message as? LightCTLStatus {
      let luminosity = UInt16(((Double(status.lightness) / 65535) * 100).rounded())
      statusManager.update(unicastAddress: source, onOff: nil, luminosity: luminosity, temperature: status.temperature, powerStatus: nil, onlineStatus: true)
    }
  }

  func model(_ model: Model, didReceiveResponse response: MeshMessage,
             toAcknowledgedMessage request: AcknowledgedMeshMessage,
             from source: Address) {
    if let status = response as? LightCTLStatus {
      let luminosity = UInt16(((Double(status.lightness) / 65535) * 100).rounded())
      statusManager.update(unicastAddress: source, onOff: nil, luminosity: luminosity, temperature: status.temperature, powerStatus: nil, onlineStatus: true)
    }
  }
}

from ios-nrf-mesh-library.

philips77 avatar philips77 commented on September 2, 2024

In that case I suspect either invalid data, or a bug in the data parser here:

public init?(parameters: Data) {
guard parameters.count == 4 || parameters.count == 9 else {
return nil
}
lightness = parameters.read()
temperature = parameters.read(fromOffset: 2)
if parameters.count == 9 {
targetLightness = parameters.read(fromOffset: 4)
targetTemperature = parameters.read(fromOffset: 6)
remainingTime = TransitionTime(rawValue: parameters[8])
} else {
targetLightness = nil
targetTemperature = nil
remainingTime = nil
}
}

Your data is FF-3F-9C-63-00-00, which is 6 bytes. This will fail on the first line. When nil is returned, the library defaults to UnknownMessage.

Let's compare with the spec...

from ios-nrf-mesh-library.

philips77 avatar philips77 commented on September 2, 2024

image

Note, that OpCode is not included here, so the data in fact should be 4 or 9 bytes long.

from ios-nrf-mesh-library.

Ahmadshoh avatar Ahmadshoh commented on September 2, 2024

Ok. Thank you very much. I will try to solve the problem using this data. I'll let you know about the results.

from ios-nrf-mesh-library.

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.