Hi,
I'm trying to control a Arduino connected RF transmitter (connected to Pin2 of my Uno) through requests sent by my internet browser. The aim is to capture a string from the internet browser (in this case ?A102) when this is typed as a suffix to the internal IP address into the address bar (so in total the link in the example below would be "192.158.0.155/?A102") and send this string (A102 in this case) to another Arduino with an RF receiver.
The RF receiver sees the string (A102) and checks against the IF statements in its own void loop to see whether the string satisfies any of the IF statements. The string A102 in this case is my instruction for receiver unit with ID "A1" to toggle pin 2.
I think I have successfully managed to compile the sketch for the receiver arduino as follows:
//RF_receiver_unit_identifier_A1
#include <VirtualWire.h>
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(2);
vw_setup(4000); // Bits per sec
//can't use pin1 as it has been set as Arduino uses it as tx pin
//can't use pin2 as it has been set as receive pin above
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
//can't use pin 01 or pin 02 as used as receive pin for rf receiver
//case for receiver identifier "A1", pin 03
if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='3')){
digitalWrite(3, !digitalRead(3));
delay(1000);
}
//case for receiver identifier "A1", pin 04
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='4')){
digitalWrite(4, !digitalRead(4));
delay(1000);
}
//case for receiver identifier "A1", pin 05
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='5')){
digitalWrite(5, !digitalRead(5));
delay(1000);
}
//case for receiver identifier "A1", pin 06
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='6')){
digitalWrite(6, !digitalRead(6));
delay(1000);
}
//case for receiver identifier "A1", pin 07
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='7')){
digitalWrite(7, !digitalRead(7));
delay(1000);
}
//case for receiver identifier "A1", pin 08
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='8')){
digitalWrite(8, !digitalRead(8));
delay(1000);
}
//case for receiver identifier "A1", pin 09
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='0')&&(buf[3]=='9')){
digitalWrite(9, !digitalRead(9));
delay(1000);
}
//case for receiver identifier "A1", pin 10
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='1')&&(buf[3]=='0')){
digitalWrite(10, !digitalRead(10));
delay(1000);
}
//case for receiver identifier "A1", pin 11
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='1')&&(buf[3]=='1')){
digitalWrite(11, !digitalRead(11));
delay(1000);
}
//case for receiver identifier "A1", pin 12
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='1')&&(buf[3]=='2')){
digitalWrite(12, !digitalRead(12));
delay(1000);
}
//case for receiver identifier "A1", pin 13
else if((buf[0]=='A')&&(buf[1]=='1')&&(buf[2]=='1')&&(buf[3]=='3')){
digitalWrite(13, !digitalRead(13));
delay(1000);
}
}
else{
delay(1000);
}
}
...but the sketch I've put together for the receiver module as follows has the following compile error:
Working_upto_pin9_withoutpagechange.ino: In function 'void checkForClient()':
Working_upto_pin9_withoutpagechange:76: error: invalid conversion from 'char' to 'const char*'
Working_upto_pin9_withoutpagechange:76: error: initializing argument 1 of 'size_t strlen(const char*)'
#include <Ethernet.h>
#include <SPI.h>
#include <VirtualWire.h>
boolean reading = false;
////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
byte ip[] = { 192, 168, 0, 155 }; //ip address to assign the arduino
byte gateway[] = { 192, 168, 0, 1 }; //ip address of the gatewa or router
//Rarly need to change this
byte subnet[] = { 255, 255, 255, 0 };
// if need to change the MAC address (Very Rare)
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////
void setup(){
//Pin 13 has LED connected to it, which we will light up during RF transmission
pinMode(13, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
vw_set_ptt_inverted(true); //
vw_set_tx_pin(2);
vw_setup(4000);// speed of data transfer Kbps
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
while (client.connected()) {
if (client.available()) {
if(!sentHeader){
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
sentHeader = true;
}
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
Serial.print(c);
vw_send((uint8_t *)c, strlen(c));
vw_wait_tx(); // Wait until the whole message is gone
delay(1000);
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
Is anybody able to tweak my code for me please to fix this issue? I think I'm close. All I'm trying to do on the transmitter side is capture the request from the browser "A102" in this case, and then send to the receiver unit so it can take the appropriate action.