Hey Guys here Is my code I am having communicating with a LoRa CLick2 device …I confirmed it communicates by hooking an Arduino to it …But the particl doesn’t seem to want to send the commands please have a look at the code and let me know whats up…
// This #include statement was automatically added by the Particle IDE.
#define LTCADDR B1100111//Table 1 both LOW (7bit address)
char B1100111;
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage, ADCvoltage, current10, current1, current0p1, current0p01;
int set_port = 1;
int incomingByte = 0;
// Some standard ports that depend on the layout of the Marvin
long defaultBaudRate = 57600;
int reset_port = 5;
int RN2483_power_port = 6; //Note that an earlier version of the Marvin doesn't support seperate power to RN2483
int led_port = 7;
//*** Set parameters here BEGIN ---->
String set_nwkskey = "923d858b2afe5cc5dc768b8b46a8932a";
String set_appskey = "e84d3cdd6b16bcb81bba3e0eb8e728a2";
String set_devaddr = "0272dff9";
String set_appeui = "fedcba9876543223";
void setup() {
Serial.begin(9600);
Serial1.begin(57600);
Particle.process();
pinMode(led_port, OUTPUT); // Initialize LED port
Wire.begin();
}
void loop() {
char message[120];
//================================
Wire.beginTransmission(LTCADDR);//first get Input Voltage - 80V max
Wire.write(0x1E);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
ADCvinMSB = Wire.read();
ADCvinLSB = Wire.read();
ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
inputVoltage = ADCvin * 0.025; //25mV resolution
Wire.beginTransmission(LTCADDR);//get ADC Input 2V max
Wire.write(0x28);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
AinVMSB = Wire.read();
AinVLSB = Wire.read();
AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
ADCvoltage = AinV * 0.5E-3; //500uV resolution
Wire.beginTransmission(LTCADDR);//get sense current
Wire.write(0x14);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
curSenseMSB = Wire.read();
curSenseLSB = Wire.read();
ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
//gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
current0p01 = ADCcur * (25E-6) / 0.01;//10A max, unit is A
//Print everything out
Serial.print("Vin:25mV/80V>");
Serial.print(inputVoltage, 2);
Serial.print("V 10ohm:2.5uA/10mA>");
Serial.print(current0p01, 3);
Serial.print("A ADC:0.5mV/2V>");
Serial.print(ADCvoltage, 4);
Serial.println("V");
delay(1000);
send_LoRa_data(set_port, String(inputVoltage,0)); //send temp / hum as rounded int over lora
delay(10000);
send_LoRa_data(set_port, String(current0p01,0)); //send_LoRa_data(set_port, String(tempdec) + "F" + String(humdec)); //send temp / hum as 4 digit integer (decimals included)
delay(10000);
//send_LoRa_data(set_port, String("123"));
//delay(10000);
blinky();
delay(1000);
read_data_from_LoRa_Mod();
}
void InitializeSerials(int baudrate)
{
delay(1000);
print_to_console("Serial ports initialised");
}
void initializeRN2483(int pwr_port, int rst_port)
{
//Enable power to the RN2483
pinMode(pwr_port, OUTPUT);
digitalWrite(pwr_port, HIGH);
print_to_console("RN2483 Powered up");
delay(1000);
//Disable reset pin
pinMode(rst_port, OUTPUT);
digitalWrite(rst_port, HIGH);
//Configure LoRa module
send_LoRa_Command("sys reset");
read_data_from_LoRa_Mod();
send_LoRa_Command("radio set crc off");
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac set nwkskey " + set_nwkskey);
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac set appskey " + set_appskey);
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac set devaddr " + set_devaddr);
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac set adr on");
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac save");
read_data_from_LoRa_Mod();
delay(1000);
send_LoRa_Command("mac join abp");
read_data_from_LoRa_Mod();
delay(1000);
}
void print_to_console(String message)
{
Serial.println(message);
}
void read_data_from_LoRa_Mod()
{
if (Serial1.available()) {
String inByte = Serial1.readString();
Serial.println(inByte);
}
}
void send_LoRa_Command(String cmd)
{
print_to_console("Now sending: " + cmd);
Serial1.printf(cmd);
Serial1.readStringUntil('\n');
delay(500);
}
void send_LoRa_data(int tx_port, String rawdata)
{
send_LoRa_Command("mac tx cnf " + String(tx_port) + String(" ") + rawdata);
}
void blinky()
{
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(led_port, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led_port, LOW); // turn the LED off by making the voltage LOW
delay(500);
}