firmata / ConfigurableFirmata

A plugin-based version of Firmata
GNU Lesser General Public License v2.1
153 stars 72 forks source link

Feature Request: 433 Mhz tx/rx support #68

Closed danielhep closed 6 years ago

danielhep commented 7 years ago

There are numerous cheap 433 Mhz receiver and transmitter pairs available on eBay. A common use for them is controlling remote controlled outlets like these ones.

There's a complete library available here which works very well for the Arduino. It would be fantastic to see this implemented in Firmata so we can see it in other platforms.

soundanalogous commented 7 years ago

I'm not going to do this work, but hopefully someone will want to take it on. The one action item for me however is to write up guidelines for how to develop 3rd party Firmata modules. An example module is here, but it's not well documented: https://github.com/firmata/FirmataEncoder.

git-developer commented 6 years ago

An implementation is available under https://github.com/git-developer/RCSwitchFirmata

soundanalogous commented 6 years ago

@git-developer I could assigned this feature a dedicated ID (rather than having to use 0x00). One other change I'd suggest is removing the RC_SEND and RC_RECEIVE pin modes since I'm planning to deprecated pin modes for non-HW pin modes, also the values assigned would conflict with pin modes already in use. I've ordered some radio modules so this is something I could also help out with over the upcoming holiday break.

git-developer commented 6 years ago

Sounds good. I would favor to see RCSwitchFirmata integrated. I remember that I tried in 2014, found an ancient pull request and the repos protocol and arduino forked. But it's been a long time since I developed the library, so I'll have to get my mind back into it.

When the pin modes are removed, what will be the replacement? Two distinct IDs?

soundanalogous commented 6 years ago

This is the proposal for replacing the use of pin modes as a feature query: https://github.com/firmata/protocol/pull/91. So in the case of RCSwitchFirmata we'd either need 2 IDs (1 for input and 1 for output), or combine input and output into a single class and use a single ID.

git-developer commented 6 years ago

I've reviewed a lot this week, found

It's quite hard for me to follow all this. I'm still trying to find out what of all this is relevant to RCSwitchFirmata. Let me sum up what I think now:

  1. RCSwitchFirmata can be categorized as an optional feature (in contrast to core features)
  2. Optional features get a centrally assigned sysex command ID that differs from (and does not start with) 0x00. They are listed in the feature registry.
  3. Currently:
    • Both RCInputFirmataand RCOutputFirmata share RESERVED_COMMAND (0x00) as sysex command ID.
    • handleCapability() is used to report capabilities to the host and returns the pin mode.
    • handlePinMode() is used to enable and disable a feature
    • handleSysex() is used for the main logic
  4. The classes RCInputFirmata and RCOutputFirmata are distinct:
    • Both classes don't depend on each other.
    • Configuration and behavior are distinct.
    • Hardware requirements differ: digital pin and 433 MHz sender for output, interrupt pin and 433 MHz receiver for input.
    • Users may use either one or both or none.

If all of this is correct, I suppose to use one feature ID for RCInputFirmata and another one for RCOutputFirmata. Using a single feature ID for both features wouldn't feel right for me.

The next steps would be per feature:

  1. Request a proposed Feature ID and replace RESERVED_COMMAND
  2. Create a pull request against firmata/protocol that adds protocol description to protocol.md
  3. Change Arduino code and bundle it as a separate Arduino library (not hosted in an official firmata repository) that may be used in conjunction with the libraries ConfigurableFirmata and rcswitch
  4. Adapt client code to these changes (I'm wrote a perl client for FHEM)

Open questions:

  1. Is this all correct?
  2. What happens to handlePinMode()?
  3. How are features enabled and disabled?
soundanalogous commented 6 years ago

In response to your assumptions above:

  1. Request 2 feature IDs, 1 for RCInputFirmata and 1 for RCOutputFirmata
  2. Create a pull request against firmata/prototcol, adding a new rcswitch-proposal.md file
  3. This is correct

What happens to handlePinMode()?

Since this feature will most likely land before the feature query is implemented (since I'm debating whether to include the new feature query it in the near future or defer it to Firmata 3.0), if you need pin modes for discovery purposes then we'll have to add them. If however the pin modes aren't absolutely necessary then simply return false from handlePinMode and stub handleCapability. The problem with pin modes as a firmware feature query is it doesn't scale well, with a high pin count board like an Arduino Mega and a few features enabled you're looking a a capability query response in excess of 500 bytes. Some client library developers have had to add 'skip capability query' functionality to avoid crashes in the case of users including a lot of features. The proposed feature query will scale much better and individual pins per feature could be requested separately if necessary.

How are features enabled and disabled?

I'm not exactly sure what you mean. Individual features are either included or not included in the sketch at compile time. You could add attach and detach methods like in the FirmataEncoder example although dynamic memory allocation can cause issues on limited RAM microcontrollers.

git-developer commented 6 years ago

Once upon a time, when I wrote RCSwitchFirmata, my understanding was:

I understand that this does not scale well. After your explanations, my understanding is now:

Did I get it right now?

soundanalogous commented 6 years ago

Yes that sound right. It also makes me realize I should define a recommendation for use of enable/disable and/or attach/detach. Attach/detach is a common Arduino pattern.

soundanalogous commented 6 years ago

Some features such as AccelStepperFirmata define enable/disable as a reflection of the enable/disable functionality of a motor driver board (see Stepper enable in the AccelStepperFirmata protocol definition). So one option would be to use enable/disable when hardware functionality is being enabled/disabled, whereas attach/detach would be used to attach or detach a firmware feature if/when it makes sense to do so (perhaps to temporarily or permanently ignore messages sent to or from a feature and free up or allocate memory if absolutely necessary).

git-developer commented 6 years ago

An implementation (work in progress) can be found under RCSwitchFirmata/dev-2.0.0.

soundanalogous commented 6 years ago

A couple of suggestions for your implementation:

git-developer commented 6 years ago

Thanks for your suggestions, I appreciate them and I'm looking forward to further comments.

git-developer commented 6 years ago

I released the implementation as RCSwitchFirmata 2.0.0.

soundanalogous commented 6 years ago

Great! I'll add it to firmatabuilder.

soundanalogous commented 6 years ago

RCOutputFirmata and RCInputFirmata are now available as selections in the Contributed features section on firmatabuilder.com.