Type cast for Serial data transmission via radio

Hello fellow arduiners.

I’m loosing a lot of hair trying to figure this one out and ask for help.

I’m assembling a RFID entrance control device that will send a RFID tag id via radio to a radio gateway to be forward to my home automation system via com port. The system must check if the tag is allowed in the house and returns a radio signal back to the RFID radio node to open the gate.

The RFID is a seedstudio 125Khz in UART mode connected to an arduino clone that has a 433Mhz Hope radio (a moteino) attached to it.

This hardware communication setup is functioning well and if I approach the tag to the RFID antena, the moteino sends a text packet to the gateway with “12345678” in it, that is the tag id, and my home automation system can deal with it for whatever purpose I want.

The problem is that I can’t figure out how to make the RFID moteino send the content of the tag.id variable to the receiver. And unless I figure out how to do this, I have to setup all the cleared tags directly on the RFID arduino sketch. And since I use the TX/RX pins to communicate with the seedstudio RFID brick, I have to disconnect the RX pin every time I want to update the cleared tags numbers.

This is the code that sends the tag id:

void loop() 
		tag = RFID.readId();

		if (tag.id == 12358867)
			Serial.print("ID (HEX):");
			Serial.print("TAG DETECTED! - Waiting for ACK...");//Send this message to the serial monitor
			if (radio.sendWithRetry(DESTINATION_NODE, "12345678", 8, 2, ACK_TIME))
				Serial.println("ACK Received!");//If the sent packet was delivered and an ACK received, send this message to the serial monitor
				delay(3);// Allow the the radio to switch to receive mode
				Blink(LED,100);//Blink the transmitter led to show the data was successfully sent

When I send Serial.println(tag.id); to the serial monitor I get the correct id 12345678.
But if I use tag.id on the transmitting command if (radio.sendWithRetry(DESTINATION_NODE, tag.id, 8, 2, ACK_TIME)) I get the following error on the compiler:

Moteino_Homeseer_RFID_Node_V0_1.ino: In function ‘void loop()’:
Moteino_Homeseer_RFID_Node_V0_1:77: error: invalid conversion from ‘long int’ to ‘const void*’
Moteino_Homeseer_RFID_Node_V0_1:77: error: initializing argument 2 of ‘bool RFM69::sendWithRetry(byte, const void*, byte, byte, byte)’

So it looks like the data to be passed to the receiver should be of the const void* type and I’m trying to pass a long int into it.

So my question is, is it possible to make the tag.id content be converted into something that will occupy the 2nd argument of sendWithRetry()?

Thank you.

I don't think there is any such thing as a const void.

You are not trying to pass a "long" number to that function, at all.

You are trying to pass a text literal to it, which would be a char*. The string "12346674" is not an integer or a long integer or any kind of number at all, it is character text.

What is the second parameter for that function call supposed to be ? Do you have the source code for it ?

michinyon: You are not trying to pass a "long" number to that function, at all.

You are trying to pass a text literal to it, which would be a char*. The string "12346674" is not an integer or a long integer or any kind of number at all, it is character text.

Well I can pass the string "12345678" alright, but I can't pass the tag id "container" which is tag.id. If I could use tag.id as an argument of the radio.sendWithRetry() function, the tag ID would be passed automatically to the function and transmitted by radio to be processed at the receiver side.

What is the second parameter for that function call supposed to be ? Do you have the source code for it ?

The second parameter is the tag identification number to be passed to the receiver.
If only I could use the tag “container”, tag.id, instead of the number itself, I could pass any tag ID number automatically to the receiver to be processed.
The function radio.sendWithRetry() is part of the library that controls the radio (https://github.com/LowPowerLab/RFM69):

// **********************************************************************************
// Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H
// **********************************************************************************
// Creative Commons Attrib Share-Alike License
// You are free to use/extend this library but please abide with the CC-BY-SA license:
// http://creativecommons.org/licenses/by-sa/3.0/
// 2013-06-14 (C) felix@lowpowerlab.com
// **********************************************************************************
#ifndef RFM69_h
#define RFM69_h
#include <Arduino.h>            //assumes Arduino IDE v1.0 or greater

#define MAX_DATA_LEN         61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead)
#define SPI_CS               SS // SS is the SPI slave select pin, for instance D10 on atmega328
#define RF69_IRQ_PIN          2 // INT0 on AVRs should be connected to DIO0 (ex on Atmega328 it's D2)
#define CSMA_LIMIT          -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
#define RF69_MODE_SLEEP       0 // XTAL OFF
#define	RF69_MODE_STANDBY     1 // XTAL ON
#define RF69_MODE_SYNTH	      2 // PLL ON
#define RF69_MODE_RX          3 // RX MODE
#define RF69_MODE_TX		      4 // TX MODE

//available frequency bands
#define RF69_315MHZ     31  // non trivial values to avoid misconfiguration
#define RF69_433MHZ     43
#define RF69_868MHZ     86
#define RF69_915MHZ     91

#define null                  0
#define COURSE_TEMP_COEF    -90 // puts the temperature reading in the ballpark, user can fine tune the returned value
#define RF69_BROADCAST_ADDR 255

class RFM69 {
    static volatile byte DATA[MAX_DATA_LEN];          // recv/xmit buf, including hdr & crc bytes
    static volatile byte DATALEN;
    static volatile byte SENDERID;
    static volatile byte TARGETID; //should match _address
    static volatile byte PAYLOADLEN;
    static volatile byte ACK_REQUESTED;
    static volatile byte ACK_RECEIVED; /// Should be polled immediately after sending a packet with ACK request
    static volatile int RSSI; //most accurate RSSI during reception (closest to the reception)
    static volatile byte _mode; //should be protected?
    RFM69(byte slaveSelectPin=SPI_CS, byte interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false) {
      _slaveSelectPin = slaveSelectPin;
      _interruptPin = interruptPin;
      _mode = RF69_MODE_STANDBY;
      _promiscuousMode = false;
      _powerLevel = 31;
      _isRFM69HW = isRFM69HW;

    bool initialize(byte freqBand, byte ID, byte networkID=1);
    void setAddress(byte addr);
    bool canSend();
    void send(byte toAddress, const void* buffer, byte bufferSize, bool requestACK=false);
    bool sendWithRetry(byte toAddress, const void* buffer, byte bufferSize, byte retries=2, byte retryWaitTime=30);
    bool receiveDone();
    bool ACKReceived(byte fromNodeID);
    void sendACK(const void* buffer = "", uint8_t bufferSize=0);
    void setFrequency(uint32_t FRF);
    void encrypt(const char* key);
    void setCS(byte newSPISlaveSelect);
    int readRSSI(bool forceTrigger=false);
    void promiscuous(bool onOff=true);
    void setHighPower(bool onOFF=true); //have to call it after initialize for RFM69HW
    void setPowerLevel(byte level); //reduce/increase transmit power level
    void sleep();
    byte readTemperature(byte calFactor=0); //get CMOS temperature (8bit)
    void rcCalibration(); //calibrate the internal RC oscillator for use in wide temperature variations - see datasheet section [4.3.5. RC Timer Accuracy]

    // allow hacking registers by making these public
    byte readReg(byte addr);
    void writeReg(byte addr, byte val);
    void readAllRegs();

    static void isr0();
    void virtual interruptHandler();
    void sendFrame(byte toAddress, const void* buffer, byte size, bool requestACK=false, bool sendACK=false);

    static RFM69* selfPointer;
    byte _slaveSelectPin;
    byte _interruptPin;
    byte _address;
    bool _promiscuousMode;
    byte _powerLevel;
    bool _isRFM69HW;

    void receiveBegin();
    void setMode(byte mode);
    void setHighPowerRegs(bool onOff);
    void select();
    void unselect();


And this is the contents of the RFID Seedstudio library that contains the processors for the tag.id calls:

#ifndef SeeedRFIDLib_h
#define SeeedRFIDLib_h

// #define DEBUG true // Use this if you want to debug your RFID stuff

#include <SoftwareSerial.h>
#include "Arduino.h"

 * Struct for storing an RFID tag
struct RFIDTag {
	int mfr;         // Manufacturer (?) Code (2 bytes), only useful in UART Mode
	long id;         // Tag ID (3 bytes)
	byte chk;        // Checksum (1 byte), only useful in UART Mode
	boolean valid;   // Validity of the Tag, based on the Checksum (UART Mode) or the parity bits (Wiegand Mode)
	char raw[13];    // The whole tag as a raw string, only useful in UART Mode

enum RFIDLibType {

#define MAX_BITS 100

// RFID Electronic Brick from Seeedstudio has 26 Bit Wiegand
#define WIEGAND_26BIT 26
#define WIEGAND_35BIT 35
 * Class for reading and checking RFID tags (UART Mode)
class SeeedRFIDLib
	SoftwareSerial * _rfidIO;
	RFIDTag _tag;
    RFIDLibType _libType;
	byte _bytesRead;
    byte _dataLen;
	boolean _idAvailable;
    volatile unsigned static char _databits[MAX_BITS];    // stores all of the data bits
    volatile unsigned static char _bitCount;
    unsigned long _facilityCode;        // decoded facility code
    unsigned long _cardCode;
    void resetWiegand();
    static void DATA0(void);
    static void DATA1(void);
    boolean checkParity26();
	boolean isIdAvailableUART();
	boolean isIdAvailableWiegand();
    SeeedRFIDLib(int rxPin, int txPin);
	SeeedRFIDLib(int dataLen);
	boolean isIdAvailable();
	RFIDTag readId();
	static long hex2dec(String hexCode);
#endif	// SeeedRFIDLib