Hi,
I am working on my arduino2arduino communication project. Want to make my gardenlights go on and off with my Android-phone (website).
I tested all parts as modules and it looks good.
I use a 433rf trans and recieve module and the virtualwire.lib.
The webserver on the transside is looking for a button to press, when it is i want to change the *msg value.
In my setup i set the msg value to: GALLO.
When the button are pressed i want to change it to: "A" / "U" / "1" etc etc.
But i can't get it to work. (the msg char is not chancing).
I think i have a problem to define the msg char.
Can anybody check my code and help me a little bit?
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
#include <SPI.h>
#include <Ethernet.h>
long versie=1556;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 254, 200 }; // ip in lan
byte gateway[] = { 192, 168, 254, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
int ledvalue=125;
int index=0;
int temp[30];
int sensorPin = A5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int sdcard=4;
int sdcardoff=HIGH;
char *msg="GALLO";
void setup(){
pinMode(5, OUTPUT); //pin selected to control
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_tx_pin(8);
vw_setup(2000); // Bits per sec
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
Serial.println(versie);
pinMode(sdcard,sdcardoff);
}
void loop(){
RFtrans();
ledcontrol();
}
int ledcontrol(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
// Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino GET test page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Arduino Webpage</H1>");
client.println("Versie: ");
client.println(versie);
client.println("
");
client.println("<b>Led
</b>");
client.println("Ledvalue:");
client.println(ledvalue);
client.println("
");
client.println("<a href=\"/?aan\"\">Led aan</a>");
client.println(" ---- ");
client.println("<a href=\"/?uit\"\">Led uit</a>
");
client.println(" ---- ");
client.println("<a href=\"/?35\"\">Led aan 1 minuut</a>");
client.println(" ---- ");
client.println("<a href=\"/?70\"\">Led aan 5 minuten</a>");
client.println(" ---- ");
client.println("<a href=\"/?150\"\">Led aan 2 uur</a>");
client.println(" ---- ");
client.println("
<b><a href=\"/\"\">Clearpage</a></b>");
client.println("</BODY>");
client.println("</HTML>");
//stopping client
client.stop();
if(readString.indexOf("?aan") >0){//checks for off
Serial.print("AAN");
const char *msg = "A";
RFtrans();
}
if(readString.indexOf("?uit") >0){//checks for off
char *msg = "U";
Serial.print("UIT");
RFtrans();
}
if(readString.indexOf("?35") >0){//checks for off
char *msg = "1";
RFtrans();
}
if(readString.indexOf("?70") >0){//checks for off
char msg = '5';
RFtrans();
}
if(readString.indexOf("?150") >0){//checks for off
char msg = '2';
RFtrans();
}
}
}
}
}
}
int RFtrans(){
Serial.print("MSG: ");
Serial.println(msg);
analogWrite(6, 255); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
analogWrite(6, 0);
delay(200);
}