Data are not passed to the database in the web server

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
thiyagarajan_mb
 
Posts: 19
Joined: Thu May 08, 2014 3:56 am

Data are not passed to the database in the web server

Post by thiyagarajan_mb »

I am using NFC, Arduino GSM shield and Arduino MEGA for a simple ticketing system application . In the below code, I am not able to transfer the data to the database in the Web Server. Fortunately, I am able to see the values of the variable through the serial monitor but the data are not transferred in the db.

I don't find any error in my code, but I am unable to see the values in my database. Kindly help me in Identifying this problem .

Code: Select all


// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ   (6)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);


// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
GSMClient client;
GPRS gprs;



//********************************************************************

int p,c;
int s ;
String source;
String destination;
char cost[10];
int total;
char people[10];



// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

// URL, path & port (for example: arduino.cc)
char server[] = "domain.com";
char path[] = "/nfctravel.php";
int port = 80; // port 80 is the default for HTTP

//**********************************************************************




    void setup()
    {
     
      // connect at 115200 so we can read the GPS fast enough and echo without dropping chars
      // also spit it out
      Serial.begin(115200);
      Serial.println("Adafruit NFC basic test!");
       boolean notConnected = true;
   
        while(notConnected)
      {
         if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
          (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
          notConnected = false;
        else
        {
          Serial.println("Not connected");
          delay(1000);
        }
      }
      Serial.println("GSM initialized");
   
 nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
    
  Serial.println("Waiting for an ISO14443A card");
  
    }
    
    void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  
  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
  
  uint32_t cardidentifier = 0;
 
   
  if (success) {
    

    
    Serial.print("Card detected #");
    // turn the four byte UID of a mifare classic into a single variable #
    cardidentifier = uid[3];
    cardidentifier <<= 8; cardidentifier |= uid[2];
    cardidentifier <<= 8; cardidentifier |= uid[1];
    cardidentifier <<= 8; cardidentifier |= uid[0];
    Serial.println(cardidentifier);
    //Serial.println("Found a card!");

          readsource ();
readdestination ();
data();

     //***************************************************************
     
      if (client.connect(server, port))
              {

                 client.print("GET /nfctravel.php?");
                 Serial.print("GET /nfctravel.php?");
                 
                 client.print("Cardno=");client.print(cardidentifier);Serial.print(cardidentifier);
                 client.print("&&Source=");client.print(source);Serial.print(source);
                 client.print("&&Destination=");client.print(destination);Serial.print(destination);
                 client.print("&&People=");client.print(p);Serial.print(p);
                 client.print("&&Cost=");client.print(c);Serial.print(c);
                 client.print("&&Total=");client.print(total);Serial.print(total);
                 
                 client.println(" HTTP/1.1");
                 Serial.println(" HTTP/1.1");
                 client.println("Host: www.domain.com");
                 Serial.println("Host: www.domain.com");
                 client.println("User-Agent: Arduino");
                 Serial.println("User-Agent: Arduino");
                 client.println("Accept: text/html");
                 Serial.println("Accept: text/html");
                 client.println("Connection: close");
                 Serial.println("Connection: close");
                 client.println();
                 Serial.println();

                 Serial.println("\nCOMPLETE!\n");
                 client.stop();
 
              }

         else
              {

                Serial.println("connection failed");
                Serial.println("\n FAILED!\n");
                client.stop();
              }
 
 
     
     
     
     
     //***************************************************************
   
    // Wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
}


void readsource ()
{
  int ss;
  Serial.print("Please enter the source location :\n");
  char sou[2];
  readSerial(sou);
  ss = atoi(sou);
  //Serial.print(ss);
  
    switch (ss) {
    case 1:    
      source = String("A");      
      //Serial.print("\nSource Location = ");
      Serial.print(source);
      break;
    case 2:    
      source = String("B");
       
      //Serial.print("\nSource Location = ");
      Serial.print(source);
      break;
    case 3:    
      source = String("C");
       
      //Serial.print("\nSource Location = ");
      Serial.print(source);
      break;
    case 4:    
      source = String("D"); 
      //Serial.print("\nSource Location = ");
      Serial.print(source);
      break;

        
    default:
   Serial.print("\nEnter correct value");
       
      }     
     
    }  
   
  


void readdestination ()
{
  int dd;
  Serial.print("\nPlease enter the destination location :\n");
   char des[2];
  readSerial(des);
  dd = atoi(des);
 // Serial.print(dd);
    switch (dd) {
    case 1:    
       destination = String("A");      
      //Serial.print(" \ndestination Location = ");
      Serial.print( destination);
      break;
    case 2:    
       destination = String("B");
       
      //Serial.print("\n destination Location = ");
      Serial.print( destination);
      break;
    case 3:    
       destination = String("C");
       
      //Serial.print("\n destination Location = ");
      Serial.print( destination);
      break;
    case 4:    
       destination = String("D"); 
      //Serial.print("\n destination Location = ");
      Serial.print( destination);
      break;
  
    default:
   Serial.print("\nEnter correct value");
       
      }     
    
    }  




void data ()
{
     Serial.print("\nPlease enter the number of people :\n");
  readSerial(people);
  p = atoi(people);
   // Serial.print ("people = ");
    Serial.print (p);
   
    Serial.print("\n Cost per head :\n");
     readSerial(cost);
     c = atoi(cost);
   // Serial.print ("\ncost = ");
    Serial.print (c);

    total = p * c;
    // Serial.print ("\ntotal =");
    // Serial.print (total);
    
  }









  int readSerial(char result[])
{
  int i = 0;
  while(1)
  {
    while (Serial.available() > 0)
    {
      char inChar = Serial.read();
      if (inChar == '\n')
      {
        result[i] = '\0';
        Serial.flush();
        return 0;
      }
      if(inChar!='\r')
      {
        result[i] = inChar;
        i++;
      }
    }
  }
}

Regarding my php file to connect with the server, Its working fine because, I used a html form to insert data in to the form and Its successfully inserting it.

Result which I get is :

Code: Select all

Adafruit NFC basic test!
GSM initialized
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A card

Card detected #56789
Please enter the source location :
A
Please enter the destination location :
D
Please enter the number of people :
2
 Cost per head :
10
Total :
20


GET /nfctravel.php?56789AD21020 HTTP/1.1
Host: http://www.domain.com
User-Agent: Arduino
Accept: text/html
Connection: close

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Data are not passed to the database in the web server

Post by adafruit_support_mike »

Do you see the requests in your webserver's access/error logs?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: Data are not passed to the database in the web server

Post by tdicola »

Like Mike mentioned, definitely check the logs to verify if requests are getting to the server and perhaps being rejected in some way. A couple other things to check:

- If you telnet to port 80 of your server and send the same message as your sketch manually, does the server respond with what you expect? This is one of the easier ways to debug HTTP & web traffic, by manually replaying messages so you can see if something is wrong with the response.

- Is your web server open to the public internet so the GSM network can reach it? When you use GSM typically your cell provider proxies the request so your providers network has to be able to access your webserver. If there's a firewall, etc. in the way it could be preventing access to your server. Telnet will again help discover these issues as it will fail to open if there's something preventing the connection from going through.

In general though be careful and think about security when you're opening a server up to the public internet. It doesn't look like there's any authentication in the web request (unfortunately auth/SSL is tough or impossible to do on Arduinos with limited memory for code) so remember anyone can start sending bogus requests to your endpoint and spamming your database with data. Just something to think about and look into possible mitigations for security issues.

thiyagarajan_mb
 
Posts: 19
Joined: Thu May 08, 2014 3:56 am

Re: Data are not passed to the database in the web server

Post by thiyagarajan_mb »

Hey guys,

To identify the problem, I just gave a simple variable (NFC cardidentifier variable) to insert into my db.

I tried with my Arduino UNO, It worked fine.
I tried with MEGA, its giving results in Serial Terminal but not storing in my db.

SAME NFC, SAME Arduino GSM shield only the change in Microcontroller. Also, I saw the Pin configuration of GSM shield for MEGA and I changed accordingly.

What and where is the problem?


I can use UNO, but because of scarcity of memory, I am going to MEGA. Have any "IDEA" guys?

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: Data are not passed to the database in the web server

Post by tdicola »

Interesting, thanks for checking that it works with an Uno. Let's check if there isn't a wiring or communication issue with the mega. Can you run the buildtest and webclient examples with the mega successfully? These should be a quick way to check if the wiring is working and basic communication with the internet works.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”