Hello,
Not really an openhab question, but maybe someone can help me:
I’m reworking an example of https://github.com/markszabo/IRremoteESP8266 to fit my need.
I’m using the example as a base https://github.com/markszabo/IRremoteESP8266/tree/master/examples/IRMQTTServer
The ESP8266 is waiting for MQTT request and send an InfraRed signal depending on the mqtt data received
What I like to do is send a infrared command as a string parameter in my MQTT request, and the ESP8266 needs to find that string in a small ‘database’ and send the correct IR.
mosquitto_pub -t "ESP8266/send_ir" -m "SAMSUNG_POWER_ON"
The context: the function receivingMQTT below is triggered every time a MQTT request is received.
Here’s what I have
samsung_code.h
// Samsung IR Code, Globalcache Format
#define SAMSUNG_POWER_OFF "38000,1,1,173,173,21,65,21,65,21,65,21,21,21,21,21,21,21,21,21,21,21,65,21,65,21,65,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,65,21,65,21,21,21,21,21,65,21,65,21,65,21,65,21,21,21,21,21,65,21,65,21,21,21,1832"
#define SAMSUNG_POWER_ON "38000,1,1,172,172,22,64,22,64,22,64,22,21,22,21,22,21,22,21,22,21,22,64,22,64,22,64,22,21,22,21,22,21,22,21,22,21,22,64,22,21,22,21,22,64,22,64,22,21,22,21,22,64,22,21,22,64,22,64,22,21,22,21,22,64,22,64,22,21,22,1820"
...
esp8266.ino
void receivingMQTT(String const topic_name, String const callback_str)
{
...
...
int ir_type = GLOBALCACHE; // >we are sending a GLOBALCACHE formatted string
char *code;
debug("Receiving data by MQTT topic " + topic_name);
debug("MQTT Payload (raw): " + callback_str);
// ->>> Here we need to affect the correct value to code
// If (callback_str =="SAMSUNG_POWER_ON") code="38000,1,1,173,173,21,.."
//
// send received MQTT value by IR signal
sendIRCode(ir_type, code,"",0, 0);
}
here’s the definition of sendIRCode, only 1st and 2nd parameters are really used in our case
// Transmit the given IR message.
//
// Args:
// ir_type: enum of the protocol to be sent.
// code: Numeric payload of the IR message. Most protocols use this.
// code_str: The unparsed code to be sent. Used by complex protocol encodings.
// bits: Nr. of bits in the protocol. 0 means use the protocol's default.
// repeat: Nr. of times the message is to be repeated. (Not all protcols.)
void sendIRCode(int const ir_type, uint64_t const code, char const *code_str,
uint16_t bits, uint16_t repeat)
So: how from the string “SAMSUNG_POWER_ON” find the string '“38000,1,1,173,173,21…”, and assign it to the the var 'code’
Thank you