WalcardAdmin
Published

Walcard, the Connected Wallet

Lose our wallet lead to wasting time and money. Walcard will help you to prevent the loss of your wallet with a history of his use.

IntermediateWork in progressOver 1 day2,159
Walcard, the Connected Wallet

Things used in this project

Hardware components

Arduino Micro
Arduino Micro
×1
Seeed Studio RFID 125kHz
×1
Sigfox TD1208
×1

Software apps and online services

BlueMix
IBM BlueMix
Sigfox
Sigfox

Hand tools and fabrication machines

RFID cards
Wallet

Story

Read more

Schematics

Node-RED functions part1

How to write in the database from Sigfox

Node-RED functions part2

How to write in the database from the webapp

Node-RED functions part3

How to write in the database from the webapp

Node-RED functions part4

How to read the database

Database

Database organization.

Database [Cards]

Cards table of the database

Database [History]

History table of the database

Database [Cards][Slot1]

Slot 1 of the Cards table

Hardware design

Database [History][Slot1]

Slot 1 of the History table

Code

Code Arduino

C/C++
To control Sigfox and RFID
#include <SoftwareSerial.h>
#include <SeeedRFID.h>

//Pins for serial connections
#define RFID_RX_PIN 10
#define RFID_TX_PIN 11
#define SIGFOX_RX_PIN 0
#define SIGFOX_TX_PIN 1

//Id of your cards
#define CARDA_ID    12994639
#define CARDB_ID    12994652
#define CARDC_ID    12994709
#define CARDD_ID    12994653

//Set up the two connections
SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
SoftwareSerial SIGFOX(SIGFOX_RX_PIN,SIGFOX_TX_PIN);

unsigned long id;

//Value of isPresent
bool CardA_value;
bool CardB_value;
bool CardC_value;
bool CardD_value;

void setup() {
  pinMode(SIGFOX_RX_PIN, INPUT);
  pinMode(SIGFOX_TX_PIN, OUTPUT);
  Serial.begin(57600);
  CardA_value = false;
  CardB_value = false;
  CardC_value = false;
  CardD_value = false;
  SIGFOX.begin(9600);
}

void loop() { 
    if(RFID.isAvailable()){
        id = RFID.cardNumber();
        Serial.print("RFID card number: ");
        Serial.println(id);
        if(id == CARDA_ID){
            CardA_value = !CardA_value;
            Serial.println(CardA_value);
            if(CardA_value == true){
                SIGFOX.print("AT$SF=0101\r");
            }
            else{
                SIGFOX.print("AT$SF=0100\r");
            }
        }
        if(id == CARDB_ID){
            CardB_value = !CardB_value;
            Serial.println(CardB_value);
            if(CardB_value == true){
                SIGFOX.print("AT$SF=0201\r");
            }
            else{
                SIGFOX.print("AT$SF=0200\r");
            }
        }
        if(id == CARDC_ID){
            CardC_value = !CardC_value;
            Serial.println(CardC_value);
            if(CardC_value == true){
                SIGFOX.print("AT$SF=0301\r");
            }
            else{
                SIGFOX.print("AT$SF=0300\r");
            }
        }
        if(id == CARDD_ID){
            CardD_value = !CardD_value;
            Serial.println(CardD_value);
            if(CardD_value == true){
                SIGFOX.print("AT$SF=0401\r");
            }
            else{
                SIGFOX.print("AT$SF=0400\r");
            }
        }
    }
}

Web app code : index.php

PHP
Main page of the Web app. Here is the part of the program that allows us to acess the database in php.
When we get the data we print them on the page and the user can see directly the content of the database on his device through a simple app. The same function can also send data to the database
 <!-- Php to access to the database -->
 <?php 
  function accessBD(&$IDdocument,&$card) {
  //API URL
    $url = 'https://walcard-node-red.eu-gb.mybluemix.net/Cards';
    //create a new cURL resource
    $ch = curl_init($url);   
    $payload = json_encode($IDdocument);
    //attach encoded JSON string to the POST fields
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

    //set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

    //return response instead of outputting
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    //execute the POST request
    $message = curl_exec($ch);

    //close cURL resource
    curl_close($ch);

    $jsonIterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(json_decode($message, TRUE)), RecursiveIteratorIterator::SELF_FIRST);

    foreach ($jsonIterator as $key => $val) {
      if(is_array($val)) {
      }
      else {
        if($key == $card['name'])
          $card['name'] = $val;
        if($key == $card['isPresent'])
          $card['isPresent'] = $val;
        if($key == $card['isImportant'])
          $card['isImportant'] = $val;
        if($key == $card['isOn'])
          $card['isOn'] = $val;
      }
    }
           
   }  
  ?> 
  
  <!-- Php to read if the card is set up or not -->
  <?php
    if (isset($_GET['isOn1'])) {
      $IDdocument = array(
        '_id' => 'Slot1',
        'isOn' => $_GET['isOn1']);

      //API URL
      $url = 'https://walcard-node-red.eu-gb.mybluemix.net/delete_Card';
      //create a new cURL resource
      $ch = curl_init($url);   
      $payload = json_encode($IDdocument);
      //attach encoded JSON string to the POST fields
      curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

      //set the content type to application/json
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

      //return response instead of outputting
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      //execute the POST request
      $message = curl_exec($ch);

      //close cURL resource
      curl_close($ch);
    }
?>

<!-- Php to read infomation about the card -->
 <?php
    $IDdocument = array(
      '_id' => 'Slot2');
      
    $card = array(
      'name' => 'name',
      'isOn' => 'isOn',
      'isImportant' => 'isImportant',
      'isPresent' => 'isPresent');
    
    $img_On = 'src/img/plus.png';

    accessBD($IDdocument,$card);

    if ($card['isOn'] == 1) { 

      echo $card['name']; 
      if ($card['isPresent'] == 0) 
        $img_present = 'src/img/cancel1.png';
      else 
        $img_present = 'src/img/checked1.png'; 

      if ($card['isImportant'] == 0) 
        $img_important = 'src/img/star.png';
      else 
        $img_important = 'src/img/star_full.png';  
  ?>

Web app code : add_card.html

HTML
The form to add a card
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"> 
    <title>Walcard</title>
    <link rel="stylesheet" href="src/css/reset.css">
    <link rel="stylesheet" href="src/css/style.css">
  </head>
  <body>
    <header>
      <h2 class="logo">
        MyWalcard
      </h2>
      </a>
       <h3 class="accueil">
        <a href="index.php"> <img src="src/img/home.png"> </a>
      </h3>
    </header>
    <h1 class="content">
      <div class="titre">
        Slot 1 : New card
      </div>
                  
      <div class="formulaire">
        <form action="cible1.php" method="post">
          <label for="fname">Card name :</label>
          <input type="text" id="nom_carte" name="nom_carte">
            Important card :
          <label class="container">Yes
            <input type="radio" name="isImportant" value="1">
            <span class="checkmark"></span>
          </label>
          <label class="container">No
            <input type="radio" name="isImportant" value="0">
            <span class="checkmark"></span>
          </label>
          
          <input type="submit" value="Confirm">
        </form>
      </div>
    </h1>
    

    <script src="src/js/script.js"></script>
  </body>
</html>

Web app code : ChangeStar.js

JavaScript
On click, to change the picture of the star if the card is favorite or not
function changeImage1()
{   
    if (document.getElementById("star1").src == "http://localhost/src/img/star.png")
    {
        document.getElementById("star1").src = "http://localhost/src/img/star_full.png";
        $("#result").load("11.php");
    }
    else
    {
        document.getElementById("star1").src = "http://localhost/src/img/star.png";
        $("#result").load("10.php");
    }
    
} 

Credits

WalcardAdmin
1 project • 1 follower

Comments