Hey Everyone,
I'm trying to send variables for the arduino to my SQL database through the PHP GET method,
Everything seems to be working just fine... Chip one sends the data to chip two, chip 2 is supposed to then send the data to the sql database. Here's the code for chip 2:
//MASTER CODE
#include <Wire.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#define disk1 0x50
SoftwareSerial SIM900(2, 3);
int Tstat = 0;
int Sstat = 0;
const int PWR = 8;
const int SIMCHK = 7;
int batt, x;
long unit, ten, hund, thou, total;
String stringOne, stringTwo, stringThree, stringFull;
void setup() {
Wire.begin(3);
Serial.begin(9600);
SIM900.begin(4800);
pinMode(PWR, OUTPUT);
pinMode(SIMCHK, INPUT);
}
void loop() {
x = 0;
int ReadEr = readEEPROM(disk1, 7);
if(ReadEr == 1){
//READ DATA OFF OF I2C EEPROM AND WRITE TO INTERNAL EEPROM
int temp1 = readEEPROM(disk1, 0);
EEPROM.write(0, temp1);
int temp2 = readEEPROM(disk1, 1);
EEPROM.write(1, temp2);
int temp3 = readEEPROM(disk1, 2);
EEPROM.write(2, temp3);
int temp4 = readEEPROM(disk1, 3);
EEPROM.write(3, temp4);
//RESET EEPROM AND SEND HANDSHAKE
writeEEPROM(disk1, 0, 0);
writeEEPROM(disk1, 1, 0);
writeEEPROM(disk1, 2, 0);
writeEEPROM(disk1, 3, 0);
writeEEPROM(disk1, 7, 2);
x = 1;
}
if(x == 1) {
batt = 0;
unit = EEPROM.read(0);
ten = (EEPROM.read(1)*10);
hund = (EEPROM.read(2)*100);
thou = (EEPROM.read(3) * 1000L);
total = thou + hund + ten + unit;
stringOne = "AT+HTTPPARA=\"URL\",\"dataden.info/WMR1.php?WMR=";
stringTwo = "&BATT=";
stringThree = "\"";
stringFull = stringOne + total + stringTwo + batt + stringThree;
SIMon();
SubmitHttpRequest();
SIMoff();
}
}
//I2C EEPROM WRITE CODE
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5);
}
//I2C EEPROM READ CODE
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
void simPWR() {
Serial.println("SIM 900 POWER PIN ACTIVE");
digitalWrite(PWR, HIGH);
delay(2500);
digitalWrite(PWR, LOW);
delay(7000);
}
void SIMon() {
Sstat = digitalRead(SIMCHK);
if(Sstat == HIGH) {
Serial.println("SIM 900 found to be off");
simPWR();
Serial.println("SIM 900 is now on");
}
else {
Serial.println("SIM 900 is on");
}
}
void SIMoff() {
Sstat = digitalRead(SIMCHK);
if(Sstat == LOW) {
Serial.println("SIM 900 found to be on");
simPWR();
Serial.println("SIM 900 is now off");
}
else {
Serial.println("SIM 900 is off");
}
}
void SubmitHttpRequest()
{
SIM900.println("AT+CSQ"); // Signal quality check
delay(100);
ShowSerialData();
SIM900.println("AT+CGATT?"); //Attach or Detach from GPRS Support
delay(100);
ShowSerialData();
SIM900.println("AT+SAPBR=0,1");//setting the SAPBR
delay(2000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"APN\",\"internet\"");//setting the APN, Access point name string
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"USER\",\"\"");//setting the APN, Access point name string
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"PWD\",\"\"");//setting the APN, Access point name string
delay(1000);
ShowSerialData();
SIM900.println("AT+SAPBR=1,1");//setting the SAPBR
delay(2000);
ShowSerialData();
SIM900.println(" AT+CIFSR"); //init the HTTP request
delay(2000);
ShowSerialData();
SIM900.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
SIM900.println(stringFull);// setting the httppara, the second parameter is the website you want to access
delay(1000);
ShowSerialData();
SIM900.println("AT+HTTPACTION=0");//submit the request
delay(10000);
ShowSerialData();
SIM900.println("AT+HTTPREAD");// read the data from the website you access
delay(300);
ShowSerialData();
SIM900.println("");
delay(100);
}
void ShowSerialData()
{
while(SIM900.available()!=0)
Serial.write(char (SIM900.read()));
}
Please see attched some shots of what it is doing in the serial monitor,
Sometimes it doesnt even finish communicating with the SIM 900 other times it gives and ERROR on AT+SAPBR=1,1 and then sometimes it UPLOADS... WFT :o !



