TOUCHDOWN!
Here is working code. Whit this i can with mymqtt android app publish topic MyMQTT/20/1/V_LIGHT with message "1" for heatpump on (with 24 degrees etc etc) and "0" for heatpump off. I have tried it with my Panasonic heatpump and it works.
I also added a little serial string in order to find out node Id (mine was 20 then)
Next step is to increase the different modes.
I was thinking from beginning of only having 5 different "hardcoded" modes that would actually be more then enough for my use, but it would be really nice to send over variables some how instead so you have complete control of the heatpump from OpenHAB (temp, heatingmode etc). I am just not sure about how long messages you can send with the nrf protocol. Must dig into that
Thanks for all the help, as I said I have almost no programming nor Arduino knowledge since before. Just starting out.
// Example sketch showing how to control ir Heatpumps
// An IR LED must be connected to Arduino PWM pin 3.
#include <Arduino.h>
#include <FujitsuHeatpumpIR.h>
#include <PanasonicCKPHeatpumpIR.h>
#include <PanasonicHeatpumpIR.h>
#include <CarrierHeatpumpIR.h>
#include <MideaHeatpumpIR.h>
#include <MitsubishiHeatpumpIR.h>
#include <SamsungHeatpumpIR.h>
#include <MySensor.h>
#include <SPI.h>
#define CHILD_1 1 // childId
IRSender irSender(3); // pin where ir diode is sitting
MySensor gw;
MyMessage msg(CHILD_1, V_VAR1);
HeatpumpIR *heatpumpIR[] = {new PanasonicCKPHeatpumpIR(), new PanasonicDKEHeatpumpIR(), new PanasonicJKEHeatpumpIR(),
new PanasonicNKEHeatpumpIR(), new CarrierHeatpumpIR(), new MideaHeatpumpIR(),
new FujitsuHeatpumpIR(), new MitsubishiFDHeatpumpIR(), new MitsubishiFEHeatpumpIR(),
new SamsungHeatpumpIR(), NULL};
// will take away everything except PanasonicJKE when everything ready to reduce sketch size
void setup()
{
gw.begin(incomingMessage); // Start listening
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("IR Sensor", "1.0");
// Register a sensors to gw. Use binary light for test purposes.
gw.present(CHILD_1, S_LIGHT);
Serial.begin(9600);
delay(500);
Serial.println(F("Starting"));
Serial.print("Node Id is set to: ");
Serial.println(gw.getNodeId());
}
void loop()
{
gw.process();
}
void incomingMessage(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_LIGHT) {
int incomingRelayStatus = message.getInt();
if (incomingRelayStatus == 1) {
int i = 0; //counter
prog_char* buf;
do {
// Send the same IR command to all supported heatpumps
Serial.print(F("Sending IR to "));
buf = (prog_char*)heatpumpIR[i]->model();
// 'model' is a PROGMEM pointer, so need to write a byte at a time
while (char modelChar = pgm_read_byte(buf++))
{
Serial.print(modelChar);
}
Serial.print(F(", info: "));
buf = (prog_char*)heatpumpIR[i]->info();
// 'info' is a PROGMEM pointer, so need to write a byte at a time
while (char infoChar = pgm_read_byte(buf++))
{
Serial.print(infoChar);
}
Serial.println();
// Send the IR command
heatpumpIR[i]->send(irSender, POWER_ON, MODE_HEAT, FAN_2, 24, VDIR_UP, HDIR_AUTO);
delay(500);
}
while (heatpumpIR[++i] != NULL);
} else if (incomingRelayStatus == 0) {
int i = 0; //counter
prog_char* buf;
do {
// Send the same IR command to all supported heatpumps
Serial.print(F("Sending IR to "));
buf = (prog_char*)heatpumpIR[i]->model();
// 'model' is a PROGMEM pointer, so need to write a byte at a time
while (char modelChar = pgm_read_byte(buf++))
{
Serial.print(modelChar);
}
Serial.print(F(", info: "));
buf = (prog_char*)heatpumpIR[i]->info();
// 'info' is a PROGMEM pointer, so need to write a byte at a time
while (char infoChar = pgm_read_byte(buf++))
{
Serial.print(infoChar);
}
Serial.println();
// Send the IR command
heatpumpIR[i]->send(irSender, POWER_OFF, MODE_HEAT, FAN_2, 24, VDIR_UP, HDIR_AUTO);
delay(500);
}
while (heatpumpIR[++i] != NULL);
}
}
}