[Solved] X10 calling function X10.sendCmd() fails

I’m building an x10 controller to manage 6 lighting fixtures with different on/off times. When I call x10.sendCmd( hcJ, 3, cmdOn) my device 3 turns on. I’m having trouble with trying to have the sketch fill in the 3 passed variables. Related to the enumerated HouseCode and CommandCode established in X10Firecraker,h Here is my sketch. Note that in column 3 of the grid I’m using 10 because housecode J is the 10th item in the enumerated list. Another thought was to use ascii code 74 to indicate J. Really appreciate your thoughts.

/*
*X10_on_off  12/6/2016  mike daly.  written for arduino uno
*uses x10firecracker.ccs with changes for newer arduino.
*other libs used as received.
*
*wiring  D2 ---> db9-7
*        D3 ---> db9-4
*       gnd ---> db9-5
*       gnd ---> rtc-gnd
*       +5v ---> rtc-vcc
*        a4 ---> rtc-SDA
*        a5 ---> rtc-SDL
*Found 1307 rtc lost time ~2hrs/24hrs
*replaced with adafruit DS3231 precision rtc
*
*
*/
#include <Wire.h>
#include <X10Firecracker.h>
#include "RTClib.h"
RTC_DS1307 RTC;
 //                                 blk to ground
#define RTS_PIN     2       // orn RTS line for C17A - DB9 pin 7
#define DTR_PIN     3       // red  DTR line for C17A - DB9 pin 4
#define BIT_DELAY   1       //  mS delay between bits (1 mS OK)
//  X10.sendCmd( hcJ, 3, cmdOn );

int hr=0 , mn=0, sec=0;
//boolean hrmatch, mnmatch, secmatch;

// h,m,s,hc,unit,on/off
int grid[12][6]={
  6,00,00,10,1,1,            // 6am lr on
  9,00,00,10,1,0,            // 9am  lr off
  15,55,00,10,1,1,            // 3:55pm lr on
  16,00,00,10,4,1,           // 4pm christmas tree
  16,30,00,10,8,1,           // 4:30pm trees on
  17,00,00,10,7,1,           // 5pm  hedges on
  17,02,00,10,5,1,            // 5pm up hall on
  21,00,00,10,5,0,            // 9pm up hall off
  22,45,00,10,8,0,            // 10:45 trees off
  22,50,00,10,7,0,            // 10:50 hedges off
  22,55,00,10,4,0,            //  10:55 christmas tree off
  23,00,00,10,1,0             //  11:00 lr off
};

int gridln=12 ;  


int    unit = 0;                           //
String house="";                     //  not currently used 
String command="";               //



void setup()
{
  X10.init(RTS_PIN, DTR_PIN, BIT_DELAY);  //
  Wire.begin();
  RTC.begin();
  Serial.begin(57600);

//  uncomment next line to set clock to compile time
//    RTC.adjust(DateTime(__DATE__, __TIME__));

  Serial.println("Serial works!");

}
 
 
void loop()
{
    DateTime now = RTC.now(); 
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    for(int i=0; i< gridln; i++)             // work through the grid to see if hour min and seconds match
      {
        if ( now.hour() == grid[i][0]) {
          if ( now.minute()== grid[i][1]){
            if (now.second() == grid[i][2]){ 
              Serial.println("BINGO");        // clock matches the grid line "i"
              // Time matches now build the x10 command from the grid 
              // if I manualy enter X10.sendCmd( hcJ, 3, cmdOn)  the light comes on
              // how can the sketch substitute a different house code, device, command that
              // matches variable types HouseCode and CommandCode?
              
             X10.sendCmd( HouseCode {grid[i][3]}, 3, CommandCode {grid[i][5]}) ;  // wont compile
            }
          }
        }
      }


 delay(1000);
}

my error messages are:

x10_on_off.ino: In function ‘void loop()’:
x10_on_off.ino:98:47: error: invalid conversion from ‘int’ to ‘HouseCode’ [-fpermissive]
x10_on_off.ino:98:76: error: invalid conversion from ‘int’ to ‘CommandCode’ [-fpermissive]
X10.sendCmd( HouseCode {grid[i][3]}, 3, CommandCode {grid[i][5]}) ;  // wont compile

Why have you got the words HouseCode and CommandCode in the call to the function ?

Either remove them or set variables with those names to the required values from the array and remove the array values from the function call.

Thank you.

I had gotten a bunch of errors with code like this.
String xx="hcJ";
String zz="cmdOn";
X10.sendCmd(xx, 3, zz);

Telling me that string is not type HouseCode

I was simply trying anything that got fewer errors .

How can I get access to the type HouseCode?

If you look at X10Firecracker.h you will see

enum HouseCode { hcA, hcB, hcC, hcD, hcE, hcF, hcG, hcH, 
				 hcI, hcJ, hcK, hcL, hcM, hcN, hcO, hcP };

enum CommandCode { cmdOn, cmdOff, cmdBright, cmdDim };

HouseCode can have a value between 0 and 16 and CommandCode a value between 0 and 3. Using enums makes the values easier to use because each has a name.

You can put the names from the enums in your arrays to make the code more readable or use the equivalent numeric values if that makes the programming easier.

UKHeliBob,

Thank you for your response. Here is a stripped down sketch that works. I’m new to C and have a long hill ahead, but I did figure out that I could do this: HouseCode xx=hcJ; and put the xx variable in my x10sendCmd(). I really like your suggestion to add the codes to my array. I thought I read that all the values in a 2dimension array had to be the same type.

If anyone else has been following, I didn’t mention that I’m using a cm17a firecracker on a uno R3 and a TM751 as the x10 receiver/xmiter. My computer runs the IDE with Ubuntu Linux. My house uses both appliance modules and lamp modules. All lamps are LEDs.

Thanks again for helping an old man out.

/*
*X10_on_off  12/6/2016  mike daly.  written for arduino uno
*uses x10firecracker.ccs with changes for newer arduino.
*other libs used as received.
*

*/
#include <Wire.h>
#include <X10Firecracker.h>
#include "RTClib.h"
RTC_DS1307 RTC;
 //                                 blk to ground
#define RTS_PIN     2       // orn RTS line for C17A - DB9 pin 7
#define DTR_PIN     3       // red  DTR line for C17A - DB9 pin 4
#define BIT_DELAY   1       //  mS delay between bits (1 mS OK)
//  X10.sendCmd( hcJ, 3, cmdOn );


void setup()
{
  X10.init(RTS_PIN, DTR_PIN, BIT_DELAY);  //
  Wire.begin();
  RTC.begin();
  Serial.begin(57600);
}
 
 
void loop()
{
              int device=1;
              HouseCode xx= hcJ;
              CommandCode zz= cmdOff;
              delay (2000);

               X10.sendCmd(xx,device, zz ) ;  
            
               xx= hcJ;
               zz= cmdOn;
              delay (2000);
              
             X10.sendCmd(xx, device, zz ) ;  


 delay(1000);
}