//transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "photon256.h"
#include "photon-beetle.h"
#include "aead.h"
#include "util.h"
TinyGPSPlus gps;
SoftwareSerial ss(2, 3);
RF24 radio(8, 7);
struct pengirimGPS{
float latitude;
float longitude;
};
pengirimGPS gpsData;
struct cipher{
unsigned char cipher1;
unsigned char cipher2;
};
cipher ctx;
struct plain{
unsigned char plain1;
unsigned char plain2;
};
plain ptx;
int enkripsi
(unsigned char *c, long long *clen,
const unsigned char *m, long long mlen,
const unsigned char *ad, long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k)
{
return photon_beetle_128_aead_encrypt
(c, clen, m, mlen, ad, adlen, nsec, npub, k);
}
static unsigned char const key[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
static unsigned char const nonce[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
static unsigned char const ad[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
void printHex(const unsigned char *data, int size) {
static unsigned char const hex[] = "0123456789abcdef";
while (size > 0) {
int b = *data++;
Serial.print(hex[(b >> 4) & 0x0F]);
Serial.print(hex[b & 0x0F]);
--size;
}
Serial.println();
}
void setup() {
Serial.begin(9600);
ss.begin(9600);
Serial.println("Setting up radio");
// Setup transmitter radio
radio.begin();
radio.openWritingPipe(0xF0F0F0F0E1LL); //untuk 1 sensor
radio.setChannel(0x76);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
radio.enableDynamicPayloads();
radio.powerUp();
Serial.println("Starting to send");
}
void GPS(){
if (gps.location.isValid()){
gpsData.longitude = gps.location.lng();
ptx.plain1 = gpsData.longitude;
//dtostrf(gpsData.longitude, 6, 3, ptx.plain1);
gpsData.latitude = gps.location.lat();
ptx.plain2 = gpsData.latitude;
//dtostrf(gpsData.latitude, 6, 3, ptx.plain2);
} else{
gpsData.longitude = 0.0;
gpsData.latitude = 0.0;
}
delay(1000);
}
void enkrip_GPS(){
enkripsi(ctx.cipher1, (6+16), ptx.plain1, 6, ad, 16, 16, nonce, key);
enkripsi(ctx.cipher2, (6+16), ptx.plain2, 6, ad, 16, 16, nonce, key);
}
void loop() {
while (ss.available() > 0){
if (gps.encode(ss.read())){
GPS();
enkrip_GPS();
//radio.write(&gpsData, 6);
radio.write(&ctx, 6+16);
Serial.print("plaintext data :");
Serial.println(ptx.plain1, 6); Serial.println(ptx.plain2, 6);
//Serial.println(gpsData.longitude,6); Serial.println(gpsData.latitude,6);
Serial.println();
Serial.println("encrypted data :");
printHex(ctx.cipher1, 6 + 16); printHex(ctx.cipher2, 6 + 16);
}
}
}
This is the library that i used:
when I uploading the .ino , the plain version of longitude and latitude, and ciphertext version of longitude and latitude is not show in serial monitor, but the compiling process is not error. what should i do? Thanks
