Code Monkey home page Code Monkey logo

Comments (3)

mikecay avatar mikecay commented on August 15, 2024

The example sketch is fine, it was not overwriting the old example when I was copy it over. However, I am still having a problem with the topic. I send homie/relay/light/on/set but it does not get received nor does anything get output to serial or sent from the lightOnHandler.

from convention.

mikecay avatar mikecay commented on August 15, 2024

given my node had 2 relays I decided to use the LedStrip sketch as my starting point for my node. This is my final sketch

`#include <Homie.h>

#define FW_NAME "ac_sw_os"
#define FW_VERSION "1.0.0"

/* Magic sequence for Autodetectable Binary Upload */
const char *__FLAGGED_FW_NAME = "\xbf\x84\xe4\x13\x54" FW_NAME "\x93\x44\x6b\xa7\x75";
const char __FLAGGED_FW_VERSION = "\x6a\x3f\x3e\x0e\xe1" FW_VERSION "\xb0\x30\x48\xd4\x1a";
/
End of magic sequence for Autodetectable Binary Upload */

const unsigned char NUMBER_OF_PLUGS = 2;
const unsigned char AC_PINS[NUMBER_OF_PLUGS] = { 12, 14 };

HomieNode plugNode("light", "switch");

bool plugHandler(const HomieRange& range, const String& value) {
plugNode.setProperty("relay").setRange(1).send("test");
Serial << "Range " << range.index << endl;
if (!range.isRange) return false; // if it's not a range

if (range.index < 1 || range.index > NUMBER_OF_PLUGS) return false; // if it's not a valid range

if (value != "on" && value != "off") return false; // if the value is not valid
bool on = (value == "on");
digitalWrite(AC_PINS[range.index - 1], on ? HIGH : LOW);
plugNode.setProperty("relay").setRange(range).send(value); // Update the state of the led
Homie.getLogger() << "Plug " << range.index << " is " << value << endl;

return true;
}

void loopHandler() {
// plugNode.setProperty("relay").setRange(1).send("test");
}

void setup() {
for (int i = 0; i < NUMBER_OF_PLUGS; i++) {
pinMode(AC_PINS[i], OUTPUT);
digitalWrite(AC_PINS[i], LOW);
}

Serial.begin(115200);
Serial << endl << endl;

Homie_setBrand("OutsideRelay"); // before Homie.setup();
Homie_setFirmware(FW_NAME, FW_VERSION);
plugNode.advertiseRange("relay", 1, NUMBER_OF_PLUGS).settable(plugHandler);
Homie.setLoopFunction(loopHandler);
Homie.setup();
}

void loop() {
Homie.loop();
}`

In the loopHandler, when I uncomment the setproperty command, my mosquitto server receives homie/plug/light/relay_1 with a payload of test. The problem is, when I send homie/plug/light/relay_1/set, I get nothing in plugHandler. is that the right topic that I should be sending to?

Thank you,

Mike

from convention.

marvinroger avatar marvinroger commented on August 15, 2024

Hi,

This is the repo of the MQTT convention, not the ESP8266 framework. Anyway, your problem is related to homieiot/homie-esp8266#250 and it was fixed there, can you please pull the latest git? It should fix it. The bug was our fault, you're not doing anything wrong.

from convention.

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.