send data string to web server from arduino + xbee


hi i'm new here, , faced problem. want receive data string , redundant data coming in form of char. here code ethernet + xbee
code: [select]
#include <spi.h>
#include <ethernet.h>
#include <softwareserial.h>
softwareserial xbee (8,7);
// assign mac address ethernet controller.
// fill in address here:
byte mac[] = {0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed};
char inchar = serial.read();
ethernetclient client;
char server[] = "192.168.0.121";
int i;

void setup() {
  xbee.begin(19200);
  serial.begin(19200);
  ethernet.begin(mac);
  serial.print("ip address        : ");
  serial.println(ethernet.localip());
}
char data =xbee.read();

void loop() {
 
if (serial.available())
  { // if data comes in serial monitor, send out xbee
    xbee.write(serial.read());
  }
  if (xbee.available())
  { // if data comes in xbee, send out serial monitor
    serial.write(xbee.read());
    char c = xbee.read();
  if (client.connect(server,80)) {
    client.print( "get /test/add_data.php?");
    client.print("kelas=");
    client.print(inchar);
    client.print("&&");
    client.print("data=");
    client.print( c );
    client.println( " http/1.1");
    client.print( "host: " );
    client.println(server);
    client.println( "connection: close" );
    client.println();
    client.println();
    client.stop();
      }
    }else {
    serial.println("connection failed");
    serial.println("disconnecting.");
  }
    delay(10000);
    }

 

i cannot use array in data receiver xbee. here xbee sender ethernet , sdcard
code: [select]
#include <spi.h>
#include <ethernet.h>
#include <softwareserial.h>
#include <sd.h>
file myfile;
byte mac[] = {
  0x90, 0xa2, 0xda, 0x00, 0xe3, 0xe0 };
ipaddress ip(192,168,0, 177);
ipaddress gateway(192,168,0, 1);
ipaddress subnet(255, 255, 255, 0);
softwareserial myserial(7, 8); // rx, tx
softwareserial xbee (6,5);
// telnet defaults port 1001
ethernetserver server(1001);
boolean alreadyconnected = false; // whether or not client connected previously
char data=(char)0;
void setup() {
  xbee.begin(19200);
  serial.begin(19200);
  // initialize ethernet device
  ethernet.begin(mac, ip, gateway, subnet);
  // start listening clients
  server.begin();
 // open serial communications , wait port open:

  serial.println("initializing sd card...");
  serial.println("chat server address:");
  serial.print(ethernet.localip());
if (!sd.begin(4)) {
    serial.println("initialization failed!");
    return;
  }
  serial.println("initialization done.");
  myfile = sd.open("ta.txt", file_write);
}
void loop() {
  // wait new client:
  ethernetclient client = server.available();
  // when client sends first byte, hello:
  if (client) {
    while(client.connected()){
    if (!alreadyconnected) {
      // clead out input buffer:
      client.flush();   
      serial.println("client connected ");
      xbee.println("a301a");
      alreadyconnected = true;
    }
    if (client.available() > 0) {
      // read bytes incoming client:
      char thischar = client.read(); 
      serial.write(thischar);
      xbee.println(thischar);
      string stringone = string (thischar);
      myfile.print(stringone);
    }
    if (myfile) {
       char thischar = client.read();
       string stringone = string (thischar);
       myfile.println("data :");
       myfile.print(stringone);
     }
    if (serial.available() > 0){
    char c=serial.read();
    client.write(c);
    xbee.println(c);
    }
    if(xbee.available()>0){
      char c=xbee.read();
      serial.write(c);
      data=c;     
      client.write(c);   
     
    char stops= 120 ;
    if(data==stops){
    client.stop();
    data=(char)0;
    alreadyconnected = false;
    delay(1000);
    serial.println("client disconected");
    client.stop();
      }
    }
    }
  }
  myfile.close();
  serial.flush();
}
sorry english

code: [select]
char inchar = serial.read();
what nonsense? haven't initialized serial instance.

code: [select]
softwareserial myserial(7, 8); // rx, tx
softwareserial xbee (6,5);

forget this. mega. can not have 2 instances of softwareserial listening @ same time. and, not have myserial connected pins. use name means something!

code: [select]
char data =xbee.read();
more useless crap.

code: [select]
  if (xbee.available())
  { // if data comes in xbee, send out serial monitor
    serial.write(xbee.read());
    char c = xbee.read();

you sending binary data serial monitor application. why sending binary data?

if 1 byte available, it's dumb idea read 2 bytes.

code: [select]
    client.print( "get /test/add_data.php?");
    client.print("kelas=");
    client.print(inchar);

send nonsense client. great idea.

code: [select]
    client.print("&&");
the separator between name=value pairs &, not &&.

code: [select]
    client.stop();
without reading server response? locked socket out of use. 4 times, sending 1 character client, , ethernet shield useless until arduino rebooted.

quote
i cannot use array in data receiver xbee. here xbee sender ethernet , sdcard
you have our permission to.

code: [select]
      string stringone = string (thischar);
      myfile.print(stringone);

wrapping 1 character in string instance ultimate in wastefulness. knock crap off.

there nothing obvious second code doing. need add comments. although suspect ctrl-a, ctrl-x better use of time.


Arduino Forum > Using Arduino > Programming Questions > send data string to web server from arduino + xbee


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code