Pages: [1]   Go Down
Author Topic: WiFly drives me crazy... simple http GET  (Read 728 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I am fighting for days now to create a simple script that writes a value with GET to a SQL database
On the ethernet Arduino i have it working but i want to do it with wifi / wifly

I tried a lot of code all over from google but i cannot get it running

Who can help me with the loop?
If it just connects and then writes a value to a "domain.com/test.php?value=12345" i am happy!!

The final plan is that the "value" comes from an id-12 rfid reader
Thanks for your help!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be helpful to see the code that you have so people can start helping you with it.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

for the loop i do not have any code because nothing is working, sorry
and to connect i use the code of example webclientgetpost.

the following from the examples puts something in the sql
Code:
void loop() {

  Serial << F("Beginning of Loop RAM:") << freeMemory() << endl ;
 
  // Perform GET example
  float fSampleValue = iLoopCounter + (iLoopCounter / 10 );

  Do_GET_Example(   iLoopCounter, fSampleValue );
 
  // Perform POST example
  Do_POST_Example ( iLoopCounter, fSampleValue );
 
  // Serial << "Clear leftovers" << endl;
  // flush the wifi buffer by reading and showing anything left around.


  while ((chMisc = wifi.read()) > -1) {
    Serial << chMisc;
  }
  iLoopCounter++;
 
  // wait a bit
  Serial << F("Waiting a moment..") << endl;
  delay(2000);
}

but i want to change this to some simple lines to put the rfid code
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And this is what i do with the Arduino ethernet, so this is what i wish ;-) to do.... finally

Code:
void loop () {
  lcd.setCursor(0,1);
  lcd.print("                ");

  byte i = 0;
  byte val = 0;
  byte code[6];
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;

  if(mySerial.available() > 0) {
    if((val = mySerial.read()) == 2) {                  // check for header

      digitalWrite(ledRfid, HIGH);   // set the LED on

      bytesread = 0;
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if( mySerial.available() > 0) {
          val = mySerial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading
            break;                                    // stop reading
          }
          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          }
          else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }
          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          }
          else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        }
      }

      // Output to Serial:
      if (bytesread == 12) {                          // if 12 digit read is complete
        Serial.print("5-byte code: ");
        for (i=0; i<5; i++) {
          if (code[i] < 16) Serial.print("0");
          Serial.print(code[i], HEX);
          Serial.print(" ");
        }
        Serial.println();
        Serial.print("Checksum: ");
        Serial.print(code[5], HEX);
        Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
        Serial.println();

        Serial.println("connecting...");
        delay(500);
        if (client.connect(server, 80)) {
          Serial.println("connected");
 
          client.print(getLine);
          for (i=0; i<5; i++) {
            if (code[i] < 16) client.print("0");
            client.print(code[i], HEX);
          }
          client.println(" HTTP/1 .1");
          client.println("Host: domain.com");
          client.println("User-Agent: arduino-ethernet");
          client.println("Connection: close");
          client.println();
          client.stop();
          digitalWrite(ledRfid, LOW);    // set the LED off

        }
        else {
          Serial.println("connection failed");

        }
      }

      bytesread = 0;
    }
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the code. I'm not the most experienced with this, but I gave your code a quick skim.

check out how i arranged my wifly code. you can see it on this: http://arduino.cc/forum/index.php/topic,119159.0.html topic.

But as the topic suggests, I also have buggy code.
Logged

Pages: [1]   Go Up
Jump to: