SW encryption

Files at this revision

API Documentation at this revision

Comitter:
liamcox94
Date:
Tue Apr 30 03:03:03 2019 +0000
Parent:
48:b2afcf2d41fb
Commit message:
Dissertation final

Changed in this revision

DummySensor.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DummySensor.h	Tue Mar 19 16:06:19 2019 +0000
+++ b/DummySensor.h	Tue Apr 30 03:03:03 2019 +0000
@@ -23,9 +23,9 @@
  */
 class DS1820 {
 public:
-    DS1820(uint32_t)
+    DS1820(uint8_t)
     {
-        value = 1.0f;
+        value = 10;
     };
     bool begin()
     {
@@ -34,7 +34,7 @@
     void startConversion() {};
     float read()
     {
-        value += 1.1f;
+        value += 1;
         return value;
     }
 
--- a/main.cpp	Tue Mar 19 16:06:19 2019 +0000
+++ b/main.cpp	Tue Apr 30 03:03:03 2019 +0000
@@ -1,19 +1,3 @@
-/**
- * Copyright (c) 2017, Arm Limited and affiliates.
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 #include <stdio.h>
 #include <iostream>
 
@@ -33,8 +17,8 @@
 // Max payload size can be LORAMAC_PHY_MAXPAYLOAD.
 // This example only communicates with much shorter messages (<30 bytes).
 // If longer messages are used, these buffers must be changed accordingly.
-uint8_t tx_buffer[44];
-uint8_t rx_buffer[44];
+uint8_t tx_buffer[128];
+uint8_t rx_buffer[128];
 
 /*
  * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing
@@ -153,41 +137,45 @@
 static void send_message() {
   uint16_t packet_cont;
   int16_t loraStatus;
-  /*****************************************************************************************************/
-
-  uint8_t hash_content = 77;
-  char hash_str[] = "";
-  sprintf(hash_str, "%d", hash_content);
-
-  static const unsigned char * hash_buffer = (const unsigned char * ) hash_str;
-  static const size_t hash_len = strlen(hash_str);
+  uint8_t hash_content;
+  uint8_t sensor_val;
   unsigned char output[32];
+  
+  //Begin sensor
+  if (ds1820.begin()) {
+        ds1820.startConversion();
+        sensor_val = ds1820.read();
+        ds1820.startConversion();
+    } else {
+        printf("\r\n No sensor found \r\n");
+        return;
+    }
 
-  mbedtls_sha256(hash_buffer, hash_len, output, 0);
+  hash_content = sensor_val;                                                    //Assign sensor value to hash_content
+  printf("\r\n %d sensor value \r\n", hash_content);                            //print to check value
+  char hash_str[] = "";                                                         //create new char array
+  sprintf(hash_str, "%d", hash_content);                                        //put value into new char array
 
-  const char * c = (const char * ) output;
+  static const unsigned char * hash_buffer = (const unsigned char * ) hash_str; //cast char array to const unsigned char
+  static const size_t hash_len = strlen(hash_str);                              //get size of message
 
-  /*****************************************************************************************************/
+
+  mbedtls_sha256(hash_buffer, hash_len, output, 0);                             //hash message
 
-  packet_cont = sprintf((char * ) tx_buffer, c);
+  const char * c = (const char * ) output;                                      //put hashed message into char
 
-  loraStatus = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_cont,
+  packet_cont = sprintf((char * ) tx_buffer, "%d%s",hash_content , c);          //build message with original value + hashed message
+
+  loraStatus = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_cont,    //send message
     MSG_UNCONFIRMED_FLAG);
 
-  if (loraStatus < 0) {
+  if (loraStatus < 0) {                                                         //perform checks to confirm message is sent
     loraStatus == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n") :
-      printf("\r\n send() - Error code %d \r\n", loraStatus);
-
-    if (loraStatus == LORAWAN_STATUS_WOULD_BLOCK) {
-      //retry in 3 seconds
-      if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
-        ev_queue.call_in(3000, send_message);
-      }
-    }
+    printf("\r\n send() - Error code %d \r\n", loraStatus);
     return;
   }
 
-  printf("\r\n %d bytes scheduled for transmission \r\n", loraStatus);
+  printf("\r\n %d bytes scheduled for transmission \r\n", loraStatus);          //print if successful and clear tx buffer
   memset(tx_buffer, 0, sizeof(tx_buffer));
 }
 /**