I am working on an environmental monitor in two parts, one half on an Uno with ethernet shield and el-cheapo 433Mhz receiver, and the other half on an Arduino Mega with a 433Mhz transmitter. Both arduinos have sensors, which are read and then posted to a MySQL DB via the ethernet shield.
The arduino mega is sending the values from its sensors via Virtual Wire to the Uno using the code below, which works fine - at least in terms of the string being visible in the serial monitor.
char msg[19];
char msglcd[19];
int whole, frac, wholep, fracp;
whole = (int)T; // Get everything before the decimal point by casting to an int
wholep = (int)P;
frac = (int)((T-whole)*10); // frac is now equal to the first number after the decimal point
fracp = (int)((P-wholep)*10); // frac is now equal to the first number after the decimal point
snprintf(msg, sizeof(msg), " T2:%i.%i P:%i.%i", whole, frac, wholep, fracp);
snprintf(msglcd, sizeof(msg), "T:%i.%i P:%i.%i", whole, frac, wholep, fracp);
lcd.setCursor(0,1);
lcd.print(msglcd);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // We wait to finish sending the message
delay(200); // We wait to send the message again
The transmitting arduino also has a PIR, which should send an "M" character via virtualwire when there is movement detected:
char msg[] = "M";
delay(300);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // We wait to finish sending the message
delay(300); // We wait to send the message again
/////motionrf
Now I'm not sure if it's the above which is the problem, or if it's at the receiving end. I do the the output from the first block of code on the receiving arduino so I know that works fine. But when the PIR is triggered, no M appears in the serial monitor of the receiver, and the code below isn't triggered either.
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
int i;
if( vw_get_message(buf, &buflen) )
{
if(pos < 2)
lcd.setCursor(0, pos);
else
{
pos=0;
lcd.clear();
}
str = "";
for (i = 1; i < buflen; i++)
{
lcd.print((char)buf[i]);
str = str + char(buf[i]);
pos++;
}
}
Serial.print("This is the string! ");
Serial.println(str);
if(str.indexOf("M") >=0)
{
digitalWrite(9, HIGH);
delay(2000);
digitalWrite(9, LOW);
str = "";
Serial.println("Detected remote movement in string!");
}
I can post the full code of both sketches if that would help more, but I am sure the issue must lie in one of those snippets of code.
Thanks for any help in advance! Shout if any info is lacking.