Fixed encryption/decryption

main
o.likhogub 1 year ago
parent ddc7babecf
commit 7820f4fb5e

@ -14,7 +14,7 @@ private:
RH_ASK *rhAsk;
public:
TransmitterModule() {
rhAsk = new RH_ASK(2000, 4, 5, 0);
rhAsk = new RH_ASK(2000, 5, 4, 0);
}
bool init() {
return rhAsk->init();

@ -15,5 +15,4 @@ framework = arduino
monitor_speed = 115200
lib_deps =
mikem/RadioHead@^1.120
bblanchon/ArduinoJson@^6.21.3
rweather/Crypto@^0.4.0

@ -12,7 +12,6 @@
#endif
#include "Uuid.h"
#include <ArduinoJson.h>
String serverName = "http://gw.cg.k-lab.su/api/v1/measures/register";
@ -99,9 +98,13 @@ bool sendPayload(MeasureData &data) {
MeasureData data;
void loop() {
data.sensor_id = 0;
data.sensor_type = 1;
data.payload = rand() & 0xffff;
sendPayload(data);
delay(5000);
if (transmissionModule.receive(sensor_id, data)) {
data.sensor_id = sensor_id;
data.sensor_type = data.sensor_type;
data.payload = data.payload;
analogWrite(LED_BUILTIN, 255);
sendPayload(data);
delay(100);
analogWrite(LED_BUILTIN, 0);
}
}

@ -25,12 +25,8 @@ void TransmissionModule::transmit(MeasureData &data)
cipher->addAuthData(authdata + posn, len);
}
for (posn = 0; posn < data_size; posn += inc) {
len = data_size - posn;
if (len > inc)
len = inc;
cipher->encrypt(buffer + posn, (uint8_t*)&data + 1 + posn, len);
}
cipher->encrypt(buffer + 1, (uint8_t*)&data, data_size);
buffer[0] = data.sensor_id;
//*************************
//Encryption Testing
@ -55,10 +51,7 @@ void TransmissionModule::transmit(MeasureData &data)
// Serial.println("works");
// }
uint8_t msg[MSG_LENGTH];
msg[0] = data.sensor_id;
memcpy(msg + 1, (void *) &data, 4);
uint8_t encoded[MSG_LENGTH + ECC_LENGTH];
reedSolomonModule->encode(msg, encoded);
reedSolomonModule->encode(buffer, encoded);
transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH);
}

@ -8,8 +8,8 @@
#ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define RH_TRANSMIT_PIN 5
#define RH_RECEIVE_PIN 4
#define RH_TRANSMIT_PIN 4
#define RH_RECEIVE_PIN 5
class TransmitterModule {
private:

Loading…
Cancel
Save