[IR] long long value and hex not taken into account

Nox we can process long long values and hex key when doing MQTTtoIR.
Also remove simpleReceiving as it only enable to use NEC or Raw
This commit is contained in:
Florian
2020-01-11 15:45:50 +01:00
parent 1cc12e2ecf
commit d4280ffde3
3 changed files with 41 additions and 134 deletions

View File

@@ -14,6 +14,11 @@ And press your IR remote control in front of the receiver led you should see the
home/OpenMQTTGateway/IRtoMQTT {"value":875849879,"protocol":7,"protocol_name":SAMSUNG,"bits":32,"raw":"4534,4432,612,518,614,516,616,1618,618,1616,618,512,618,1618,608,524,612,518,616,514,618,512,616,1618,616,1618,618,514,616,1618,616,514,616,514,618,512,616,1618,618,1618,618,514,610,1622,616,514,618,514,614,516,616,1618,618,512,618,512,618,1616,550,580,618,1616,612,1624,618,1616,618"}
```
With an hexadecimal value:
```
{"value":9938405643,"protocol":55,"bits":35,"hex":"0x25060090B","protocol_name":"TECO"}
```
To receive big dump of raw data you need first to modify the [config_IR.h](https://github.com/1technophile/OpenMQTTGateway/blob/091b317660fd201a30e2cd0e15424a13c5a6bd71/config_IR.h#L41) and uncomment DumpMode true
Unknown protocols are filtered by default, if you want to see the unknown protocols set into [config_IR.h](https://github.com/1technophile/OpenMQTTGateway/blob/master/config_IR.h)
@@ -34,6 +39,9 @@ For example if I want to send a command to a sony TV you can use the following c
The code after the -m represent the payload you want to send.
You could alternatively use an hex value:
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoIR -m '{"hex":"0x25060090B","protocol_name":"TECO"}'`
If you dont want to use special parameters for IR just use value key, the protocol per default is NEC
`mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoIR -m '{"value":551489775}'`

View File

@@ -75,6 +75,25 @@ IRsend irsend; //connect IR emitter pin to D9 on arduino, you need to comment #d
#define WHYNTER_BITS 32U
#endif
// The function below comes from IRMQTTServer.INO on IRremoteESP8266 project from @crankyoldgit
uint64_t getUInt64fromHex(char const *str) {
uint64_t result = 0;
uint16_t offset = 0;
// Skip any leading '0x' or '0X' prefix.
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) offset = 2;
for (; isxdigit((unsigned char)str[offset]); offset++) {
char c = str[offset];
result *= 16;
if (isdigit(c))
result += c - '0'; // '0' .. '9'
else if (isupper(c))
result += c - 'A' + 10; // 'A' .. 'F'
else
result += c - 'a' + 10; // 'a' .. 'f'
}
return result;
}
void setupIR()
{
//IR init parameters
@@ -107,7 +126,7 @@ void IRtoMQTT()
taskMessage = taskMessage + xPortGetCoreID();
trc(taskMessage);
#endif
IRdata.set("value", (unsigned long)(results.value));
IRdata.set("value", (unsigned long long)(results.value));
IRdata.set("protocol", (int)(results.decode_type));
IRdata.set("bits", (int)(results.bits));
#if defined(ESP8266) || defined(ESP32) //resultToHexidecimal is only available with IRremoteESP8266
@@ -150,8 +169,8 @@ void IRtoMQTT()
trc(F("raw redirected"));
#endif
irrecv.resume(); // Receive the next value
unsigned long MQTTvalue = IRdata.get<unsigned long long>("value");
trc(MQTTvalue);
unsigned long long MQTTvalue = IRdata.get<unsigned long long>("value");
//trc(MQTTvalue);
if ((pubIRunknownPrtcl == false && IRdata.get<int>("protocol") == -1) /*|| MQTTvalue == ULONG_MAX*/)
{ // don't publish unknown IR protocol or data to high
trc(F("--no pub unknwn prt or data to high--"));
@@ -171,134 +190,6 @@ void IRtoMQTT()
}
}
#ifdef simpleReceiving
void MQTTtoIR(char *topicOri, char *datacallback)
{
// IR DATA ANALYSIS
//send received MQTT value by IR signal
bool signalSent = false;
uint64_t data = 0;
String strcallback = String(datacallback);
trc(datacallback);
unsigned int s = strcallback.length();
//number of "," value count
int count = 0;
for (int i = 0; i < s; i++)
{
if (datacallback[i] == ',')
{
count++;
}
}
if (count == 0)
{
data = strtoul(datacallback, NULL, 10); // standard sending with unsigned long, we will not be able to pass values > 4294967295
}
#ifdef IR_GC
else if (strstr(topicOri, "GC") != NULL)
{ // sending GC data from https://irdb.globalcache.com
trc(F("GC"));
//buffer allocation from char datacallback
uint16_t GC[count + 1];
String value = "";
int j = 0;
for (int i = 0; i < s; i++)
{
if (datacallback[i] != ',')
{
value = value + String(datacallback[i]);
}
if ((datacallback[i] == ',') || (i == s - 1))
{
GC[j] = value.toInt();
value = "";
j++;
}
}
irsend.sendGC(GC, j);
signalSent = true;
}
#endif
#ifdef IR_RAW
else if (strstr(topicOri, "Raw") != NULL)
{ // sending Raw data
trc(F("Raw"));
//buffer allocation from char datacallback
#if defined(ESP8266) || defined(ESP32)
uint16_t Raw[count + 1];
#else
unsigned int Raw[count + 1];
#endif
String value = "";
int j = 0;
for (int i = 0; i < s; i++)
{
if (datacallback[i] != ',')
{
value = value + String(datacallback[i]);
}
if ((datacallback[i] == ',') || (i == s - 1))
{
Raw[j] = value.toInt();
value = "";
j++;
}
}
irsend.sendRaw(Raw, j, RawFrequency);
signalSent = true;
}
#endif
//We look into the subject to see if a special Bits number is defined
String topic = topicOri;
unsigned int valueBITS = 0;
int pos = topic.lastIndexOf(IRbitsKey);
if (pos != -1)
{
pos = pos + +strlen(IRbitsKey);
valueBITS = (topic.substring(pos, pos + 2)).toInt();
trc(F("Bits nb:"));
trc(valueBITS);
}
//We look into the subject to see if a special repeat number is defined
uint16_t valueRPT = 0;
int pos2 = topic.lastIndexOf(IRRptKey);
if (pos2 != -1)
{
pos2 = pos2 + strlen(IRRptKey);
valueRPT = (topic.substring(pos2, pos2 + 1)).toInt();
trc(F("IR repeat:"));
trc(valueRPT);
}
if (topicOri && (strstr(topicOri, "NEC") == NULL))
{
trc("SendId prt");
signalSent = sendIdentifiedProtocol(topicOri, data, datacallback, valueBITS, valueRPT);
}
else
{
trc(F("Not identified prt using NEC"));
if (valueBITS == 0)
valueBITS = NEC_BITS;
#if defined(ESP8266) || defined(ESP32)
irsend.sendNEC(data, valueBITS, valueRPT);
#else
for (int i = 0; i <= valueRPT; i++)
irsend.sendNEC(data, valueBITS);
#endif
signalSent = true;
}
if (signalSent)
{ // we acknowledge the sending by publishing the value to an acknowledgement topic, for the moment even if it is a signal repetition we acknowledge also
pub(subjectGTWIRtoMQTT, datacallback);
}
irrecv.enableIRIn(); // ReStart the IR receiver (if not restarted it is not able to receive data)
}
#endif
#ifdef jsonReceiving
void MQTTtoIR(char *topicOri, JsonObject &IRdata)
{
@@ -309,6 +200,10 @@ void MQTTtoIR(char *topicOri, JsonObject &IRdata)
uint64_t data = IRdata["value"];
const char *raw = IRdata["raw"];
const char *datastring = IRdata["datastring"];
const char *hex = IRdata["hex"];
if (hex) {// we privilegiate the hex usage over the value one (less risk of error)
data = getUInt64fromHex(hex);
}
if (data != 0 || raw || datastring)
{
trc(F("MQTTtoIR value || raw || datasring ok"));

View File

@@ -431,6 +431,13 @@ void pubMQTT(char *topic, unsigned long payload)
client.publish(topic, val);
}
void pubMQTT(char *topic, unsigned long long payload)
{
char val[21];
sprintf(val, "%llu", payload);
client.publish(topic, val);
}
void pubMQTT(char *topic, String payload)
{
client.publish(topic, (char *)payload.c_str());
@@ -1461,9 +1468,6 @@ void receivingMQTT(char *topicOri, char *datacallback)
#ifdef ZgatewaySRFB
MQTTtoSRFB(topicOri, datacallback);
#endif
#ifdef ZgatewayIR
MQTTtoIR(topicOri, datacallback);
#endif
#ifdef ZgatewayRFM69
MQTTtoRFM69(topicOri, datacallback);
#endif