Hello, this is my first post on this forum, because I dont know where else to go. My project is an attendance rfid system that uses google sheets. it uses the arduino uno, ethernet shield, rc522 reader. I have the card identified, then it uploads to the pushingbox api, and that uses the google script code, which puts the data on the spreadsheet. this is the arduino code
/* Arduino Code which sends data to google spreadsheet */
#include<SPI.h>
#include<MFRC522.h>
#include <Ethernet.h>
#define SS_PIN 4 //FOR RFID SS PIN BECASUSE WE ARE USING BOTH ETHERNET SHIELD AND RS-522
#define RST_PIN 9
#define No_Of_Card 3
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "api.pushingbox.com"; //YOUR SERVER
IPAddress ip(*my ip is here im just not uploading it to the world*);
EthernetClient client;
MFRC522 rfid(SS_PIN,RST_PIN);
MFRC522::MIFARE_Key key;
byte id[No_Of_Card][4]={
{121,211,95,99}, //RFID NO-1
{3010,9,31,52}, //RFID NO-2
{142,76,58,42} //RFID NO-3
};
byte id_temp[0][0];
byte i;
int j=0;
// the setup function runs once when you press reset or power the board
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
for(byte i=0;i<6;i++)
{
key.keyByte[i]=0xFF;
}
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
}
// the loop function runs over and over again forever
void loop(){
int m=0;
if(!rfid.PICC_IsNewCardPresent())
return;
if(!rfid.PICC_ReadCardSerial())
return;
for(i=0;i<4;i++)
{
id_temp[0][i]=rfid.uid.uidByte[i];
delay(50);
}
for(i=0;i<No_Of_Card;i++)
{
if(id[i][0]==id_temp[0][0]) {
Serial.print("your card no :");
for(int s=0;s<3;s++)
{
Serial.print(rfid.uid.uidByte[s]);
Serial.print(" ");
}
Serial.println("\nValid Person");
Sending_To_spreadsheet();
j=0;
rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return;
}
else if(id[i][1]==id_temp[0][1]) {
Serial.print("your card no :");
for(int s=0;s<3;s++)
{
Serial.print(rfid.uid.uidByte[s]);
Serial.print(" ");
}
Serial.println("\nValid Person");
Sending_To_spreadsheet();
j=0;
rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return;
}
else if(id[i][2]==id_temp[0][2]) {
Serial.print("your card no :");
for(int s=0;s<3;s++)
{
Serial.print(rfid.uid.uidByte[s]);
Serial.print(" ");
}
Serial.println("\nValid Person");
Sending_To_spreadsheet();
j=0;
rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return;
}
else if(id[i][3]==id_temp[0][3])
{
Serial.print("your card no :");
for(int s=0;s<3;s++)
{
Serial.print(rfid.uid.uidByte[s]);
Serial.print(" ");
}
Serial.println("\nValid Person");
Sending_To_spreadsheet();
j=0;
rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); return;
}
else if(i<3)
{j++;
if(j==0)
{
Serial.println("Not a valid Person");
Sending_To_spreadsheet();
j=0;
}
}
}
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}
void Sending_To_spreadsheet() //CONNECTING WITH MYSQL
{
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.print("GET /pushingbox?devid=v4C30CA17D5F64E2&allowed_members="); //YOUR URL
if(j==0)
{
client.print('1');
Serial.print('1');
}
else
{
client.print('0');
}
client.print("&Member_ID=");
for(int s=0;s<4;s++)
{
client.print(rfid.uid.uidByte[s]);
}
client.print(" "); //SPACE BEFORE HTTP/1.1
client.print("HTTP/1.1");
client.println();
client.println("Host: api.pushingbox.com");
client.println("Connection: close");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
I dont think that code is the problem, so here is the google code:
function doGet(e) {
Logger.log( JSON.stringify(e) );
var result = 'Ok';
if (e.parameter == undefined) {
result = 'No Parameters';
}
else {
var id = '1mu_ae80OFd4kztw5x-vqOcGQvdpwBR2znduJqMsmms0'; // Spreadsheet ID
var sheet = SpreadsheetApp.openById(id).getActiveSheet();
var newRow = sheet.getLastRow() + 1;
var rfidData = [];
rfidData[0] = new Date();
for (var param in e.parameter) {
Logger.log('In for loop, param='+param);
var value = stripQuotes(e.parameter[param]);
switch (param) {
case 'allowed_members': //Parameter
rfidData[1] = value; //Value in column B
break;
case 'Member_ID':
rfidData[2] = value;
break;
default:
result = "Wrong parameter";
}
}
Logger.log(JSON.stringify(rfidData));
// Write new row below
var newRange = sheet.getRange(newRow, 1, 1, rfidData.length);
newRange.setValues([rfidData]);
}
// Return result of operation
return ContentService.createTextOutput(result);
}
/**
* Remove leading and trailing single or double quotes
*/
function stripQuotes( value ) {
return value.replace(/^["']|['"]$/g, "");
}
/* most of the code is originally from embedotronic technologies so thank you*/
it literally identifies everything, it just wont write any data to spreadsheet and I dont know why. please help me lol