0

I want to upload/pubish RAW IR Code to MQTT server received through my ESP8266. I have received the following RAW IR code from the Television using the IR receiver sensor:

RAW IR CODE = {
  4650,4250, 700,1550, 650,1550, 700,1550, 650,450,
  650,500, 600,500, 600,500, 600,550, 550,1700, 550,
  1650, 600,1650, 550,550, 600,500, 600,550, 550,550, 
  600,500, 600,550, 550,1650, 600,550, 550,550, 600,500, 
  600,550, 550,550, 600,500, 600,1650, 600,500, 600,1650, 
  550,1700, 550,1650, 600,1650, 550,1650, 600,1650, 600
}

I want to create a new variable with the following structure:

value = RAW IR CODE+";" + "ESP8266-01"(This is the ID of the esp8266) 


value =  {
  4650,4250, 700,1550, 650,1550, 700,1550, 650,450, 650,500, 
  600,500, 600,500, 600,550, 550,1700, 550,1650, 600,1650, 550,550,
  600,500, 600,550, 550,550, 600,500, 600,550, 550,1650, 600,550, 
  550,550, 600,500, 600,550, 550,550, 600,500, 600,1650, 600,500, 
  600,1650, 550,1700, 550,1650, 600,1650, 550,1650, 600,1650, 
  600
}; ESP8266-01

I am unsure: which data type do I need to save the variable value so that it can later be retrieved/subscribed and sent to another IR sender using irsend.sendRaw, because I want to split the variable "value" into 2 parts after receiving it, the ID and the RAW code. After getting the RAW code, I want to use the irsend.sendRaw(RAW CODE, length of RAW , 38).

Could someone help me?

My attempts:
At first I tried to save it as a string, so that it can be retrieved and separated for irsend.sendRaw. However I am unable to compile it.

This is the code which I used to upload:

      /*
     * IRremoteESP8266: IRServer - MQTT IR server
     * An IR LED must be connected to ESP8266 RX port (GPIO-3)
     * An IR receiver to GPIO 0
     * used library:
     * https://github.com/markszabo/IRremoteESP8266
     */    
    #include <WiFiClient.h>

   #include <ESP8266WiFi.h>

 #include <IRremoteESP8266.h>
    #include <PubSubClient.h>
    int RECV_PIN = 0; //an IR detector/demodulator is connected to GPIO pin 0

    IRrecv irrecv(RECV_PIN);
    decode_results results;

    const char* ssid = "MY-SSID";
    const char* password = "MY-WIFI-PSK";

    const char* topicRaportPrefix = "esp8266/02/info/";
    const char* topicSubscribe = "esp8266/02/sender/#";
    const char* topicPrefix = "esp8266/02/";

    const char* mqtt_server = "10.10.10.10";
    const char* mqtt_user = "mqtt_user";
    const char* mqtt_pass = "mqtt_pass";

    String clientName; // MQTT client name
    char message_buff[100];


     void dump(decode_results *results) {
        const int count = results->rawlen;
          Serial.println(c);
          c++;
          Serial.println("For IR Remote ");
          for (int i = 1; i < count; i++) {

          if ((i % 2) == 1) {
            Serial.print("+");
            Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
        uint16_t  raw_ir_code[count] = results->rawbuf[i]*USECPERTICK;
            client.publish( "esp8266/02/sender", raw_ir_code);

After doing the changes proposed, I still get an error in compiling:

no matching function for call to 'PubSubClient::publish(const char [18], uint16_t [(int)count])'

  • Check the prototype for the publish() member function and cast the parameter to the expected type. Check that null terminated string is not assumed. In that case you will have to do the conversion. The member function should have at least three parameters to work; topic, data pointer, number of data bytes. – Mikael Patel May 28 '16 at 9:53
1

First create a topic and include the ESP8266 ID. Do not make it part of the published value.

Second publish the raw data as-is, uint16_t raw_ir_code[RAW_IR_CODE_MAX]. The alternative is to convert to string (characters). But if the subscriber has the same architecture (interpretation of data), there is no need to convert it to string and back. Simply publish the raw data as it is.

You will need to cast the raw_ir_code vector to the appropriate type for the MQTT publish call.

Cheers!

  • Could you explain how to retrieve the value from the mqtt server. – qwerty May 27 '16 at 14:44
  • 1
    What library are you using? – Mikael Patel May 27 '16 at 21:10
  • Esp8266IRremote – qwerty May 27 '16 at 23:40
  • And what library for MQTT? – Mikael Patel May 27 '16 at 23:42
  • No specific library but using the code for normal connection with Mqtt server. – qwerty May 28 '16 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.