Leo Palazzi
Published

Long Life - Connected Wallet

IoT is now everywhere. Here you will find all the steps to make a connected wallet yourself.

AdvancedFull instructions providedOver 1 day87
Long Life - Connected Wallet

Things used in this project

Hardware components

nRF51822 Bluetooth Smart Beacon Kit
Nordic Semiconductor nRF51822 Bluetooth Smart Beacon Kit
×1
Breakout Sigfox BRKWS01
×1
Grove GPS
×1

Software apps and online services

Android Studio
Android Studio
BlueMix
IBM BlueMix

Story

Read more

Schematics

Hardware

Code

Mobile application

Java
It is used to find your connected wallet.
No preview (download only).

Firmware_NRF51822.cpp

C/C++
The code is used to program the NRF51822.
/*

Copyright (c) 2012-2014 RedBearLab

Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
and associated documentation files (the "Software"), to deal in the Software without restriction, 
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

/*
 *    The application works with the BLEController iOS/Android App.
 *    Type something from the Terminal to send
 *    to the BLEController App or vice verse.
 *    Characteristics received from App will print on Terminal.
 */
 
#include "mbed.h"
#include "ble/BLE.h"


#define BLE_UUID_TXRX_SERVICE            0x0000 /**< The UUID of the Nordic UART Service. */
#define BLE_UUID_TX_CHARACTERISTIC       0x0002 /**< The UUID of the TX Characteristic. */
#define BLE_UUIDS_RX_CHARACTERISTIC      0x0003 /**< The UUID of the RX Characteristic. */

#define TXRX_BUF_LEN                     20

BLE  ble;

PwmOut Alim_Sigfox(D13);
DigitalOut Alim_GPS(P0_19);
Serial sigfox(P0_9,P0_11,NULL,9600);
DigitalOut Buzzer(P0_17);

PwmOut buzzer(P0_23);
int frequency[] = {262, 800,196, 851, 525, 451, 578, 1262};
int beat[] = {4, 8, 8, 4,4,4,4,4 };
int bip = 0;
Serial device(P0_9,P0_11,NULL,9600);
unsigned char buffer[200];

void buzzer_on() {
    while(1) {
        for (int i = 0; i < (sizeof(frequency) / sizeof(int)); i++) {
            buzzer.period(1.0 / frequency[i]);
            buzzer.write(0.5);
            wait(1.0 / beat[i]);
            buzzer.write(0);
            wait(0.05);
        }
    }
}

unsigned char* trame_gps() {
    Alim_GPS=1;
    int i=0;
    char c1,c2,c3,c4,c5,c6;
    char x='x';
         if(device.readable()) 
                {
                c1 = device.getc();
                c2 = device.getc();
                c3 = device.getc();
                c4 = device.getc();
                c5 = device.getc();
                c6 = device.getc();
                if(c1== '$' && c2 == 'G' && c3 == 'P' && c4 == 'G' && c5 == 'G' && c6== 'A')
                { // Si l'on  une trame GPGPA 
                    device.getc();
                    while(device.getc() != ',')
                    {
                    }
                    
                    while(x!= 'E') // On remplit le buffer en ne conservant que l'heure, la latitude et la longitude 
                    {
                        x=device.getc();
                       // pc.putc(x);    
                        buffer[i]= x;
                        i++;
                    }    
                    buffer[i]=('\0');
                    i=0;
                    x=' ';                        
                }
        
        }         
    Alim_GPS = 0;
    return buffer;
}  
void sigfox_pos() {
       //On alimente le module 
       Alim_Sigfox.write(0.66f);
       
      //  "064036.289,4850.4313,N,00221.2453"; // Exemple de trame reu
   unsigned char* pos =trame_gps();
     
    char longitudeH[3];
    char longitudeM[3];
    char longitudeS[5];
    char latitudeH[3];
    char latitudeM[3];
    char latitudeS[5];
    int i;
    for(i=0 ; i < 2 ; i++){

        longitudeH[i] = pos[i+11];
        latitudeH[i]= pos[i+23];
        longitudeM[i] = pos[i+13];
        latitudeM[i]= pos[i+26];
        longitudeS[i] = pos[i+16];
        latitudeS[i]= pos[i+29];
        
    }
    for(i=2 ; i < 4 ; i++){
        longitudeS[i] = pos[i+16];
        latitudeS[i]= pos[i+29];
    }
latitudeH[1]= pos[25];
    int longit = atoi(longitudeH);
    int latit = atoi(latitudeH);
    int longitM = atoi(longitudeM);
    int latitM = atoi(latitudeM);
    int longitS = atoi(longitudeS);
    int latitS = atoi(latitudeS);
    // On passe du format dcimale au format radiale
    float lng = longit + (longitM*1.0 + longitS*1.0/6000)/60;
    float lat = latit + latitM*1.0/60 + latitS*1.0/360000;
    unsigned int ln=lng*10000;
    unsigned int lt=lat*10000;
    wait_ms(100);
 // On envoie sur Sigfox en Hexadcimale
    sigfox.printf("AT$SF=000%x0000%x\r\n",ln,lt );
    wait_ms(100);
    Alim_Sigfox.write(0);
}


// The Nordic UART Service
static const uint8_t uart_base_uuid[] = {0x71, 0x3D, 0, 0, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_tx_uuid[]   = {0x71, 0x3D, 0, 3, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_rx_uuid[]   = {0x71, 0x3D, 0, 2, 0x50, 0x3E, 0x4C, 0x75, 0xBA, 0x94, 0x31, 0x48, 0xF1, 0x8D, 0x94, 0x1E};
static const uint8_t uart_base_uuid_rev[] = {0x1E, 0x94, 0x8D, 0xF1, 0x48, 0x31, 0x94, 0xBA, 0x75, 0x4C, 0x3E, 0x50, 0, 0, 0x3D, 0x71};


uint8_t txPayload[TXRX_BUF_LEN] = {0,};
uint8_t rxPayload[TXRX_BUF_LEN] = {0,};

static uint8_t rx_buf[TXRX_BUF_LEN];
static uint8_t rx_len=0;


GattCharacteristic  txCharacteristic (uart_tx_uuid, txPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE);
                                      
GattCharacteristic  rxCharacteristic (uart_rx_uuid, rxPayload, 1, TXRX_BUF_LEN, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY);
                                      
GattCharacteristic *uartChars[] = {&txCharacteristic, &rxCharacteristic};

GattService         uartService(uart_base_uuid, uartChars, sizeof(uartChars) / sizeof(GattCharacteristic *));



void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
    ble.startAdvertising();
    //On envoie le messahe sigfox lorsque l'on perd la connexion
    sigfox_pos();
    buzzer_on();
}

void uartCB(void)
{   
    while(sigfox.readable())    
    {
        rx_buf[rx_len++] = sigfox.getc();    
        if(rx_len>=20 || rx_buf[rx_len-1]=='\0' || rx_buf[rx_len-1]=='\n')
        {
            ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), rx_buf, rx_len); 
           // sigfox.printf("RecHandler \r\n");
           // sigfox.printf("Length: ");
           // sigfox.putc(rx_len);
           // sigfox.printf("\r\n");
            rx_len = 0;
            break;
        }
    }
}
void WrittenHandler(const GattWriteCallbackParams *Handler)
{   
    uint8_t buf[TXRX_BUF_LEN];
    uint16_t bytesRead, index;
    
    if (Handler->handle == txCharacteristic.getValueAttribute().getHandle()) 
    {
        ble.readCharacteristicValue(txCharacteristic.getValueAttribute().getHandle(), buf, &bytesRead);
    if(bytesRead == 't')
        buzzer_on();    
    }
}
int main(void)
{
    ble.init();
    ble.onDisconnection(disconnectionCallback);  
    ble.onDataWritten(WrittenHandler);  
  
    sigfox.baud(9600);
  //  sigfox.printf("SimpleChat Init \r\n");
    
//    sigfox.attach( uartCB , sigfox.RxIrq);
   // setup advertising 
    ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
    ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
                                        (const uint8_t *)"Biscuit", sizeof("Biscuit") - 1);
    ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
                                    (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid));
    // 100ms; in multiples of 0.625ms. 
    ble.setAdvertisingInterval(160);

    ble.addService(uartService);
    
    ble.startAdvertising(); 
   // sigfox.printf("Advertising Start \r\n");
    
    while(1)
    {
        
         if(sigfox.readable()) 
                {
                bip = sigfox.getc();
                sigfox.printf("Message recu");
                }
        if(bip)
            buzzer_on();
        ble.waitForEvent(); 
    }
}

Credits

Leo Palazzi

Leo Palazzi

1 project • 0 followers

Comments