Hello.
I'm trying to send an unsigned long value through a 433MHz rf transmitter to its receiver using VirtualWire. I have been able to send the value over to the receiver. In fact, I have been able to receive the correct value successfully.
Now, what I want to achieve is to put that "long" value (which I initially sent from the transmitter) I receive on my serial monitor (perhaps characters) into a long variable. After that, I should be able to serialprint it to confirm my success. Below are by codes.
#Transmitter Code
#include <VirtualWire.h>
#include <SoftwareSerial.h>
#include <TrueRandom.h>
#include <EEPROM.h>
char *controller;
int aa = 0;
int ss, uu, tt;
int addra = 0;
int addro = 1;
String str;
unsigned long kk;
char cstr[16];
String value;
SoftwareSerial bluetooth(7, 8); // (RXD, TXD) of HC-06
//connect 7 to btm's TX
//connect 8 to btm's RX
void setup()
{
Serial.begin(9600); // start serial communication at 9600bps
bluetooth.begin(9600);
pinMode(13, OUTPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(3);
vw_setup(4000);// speed of data transfer Kbps
if (tt == 0)
{
Serial.println(EEPROM.read(addro));
EEPROM.get(addra, kk);
Serial.println(kk);
tt = 1;
}
}
void loop()
{
while (bluetooth.available())
{
char c=bluetooth.read();
if(c=='#')
{
break;
}
value += c;
}
str = String(kk);
str.toCharArray(cstr,16);
if (value.length() > 0)
{
if (value == "abc")
{
controller = cstr;
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, HIGH);
bluetooth.println(cstr);
delay(2000);
digitalWrite(13, LOW);
delay(100);
}
if (value == "xyz")
{
controller = "12345678";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
//digitalWrite(13, LOW);
bluetooth.println("Zero Sent");
delay(2000);
}
value="";
}
}
#Receiver Code
#include <VirtualWire.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(7, 8); // (RXD, TXD) of HC-06
//connect 7 to btm's TX
//connect 8 to btm's RX
String str;
int aa, bb;
unsigned long num2;
char cstr[16];
unsigned long zz[5];
char msg[24];
void setup()
{
Serial.begin(9600);
Serial.println("Listening");
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(4);
vw_setup(4000);
vw_rx_start();
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
uint8_t message[VW_MAX_MESSAGE_LEN];
uint8_t messageLength = VW_MAX_MESSAGE_LEN;
if (vw_get_message(message, &messageLength))
{
for (int i = 0; i < messageLength; i++)
{
//Serial.println(message*);*
_ Serial.write(message*);_
_ }_
_ Serial.println();_
_ }*_
}
So, I would like to save the String "12345678" into a long variable at my receiver end.
Kindly help out.
Thanks.