Fixed encryption/decryption

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

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

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

@ -12,7 +12,6 @@
#endif #endif
#include "Uuid.h" #include "Uuid.h"
#include <ArduinoJson.h>
String serverName = "http://gw.cg.k-lab.su/api/v1/measures/register"; String serverName = "http://gw.cg.k-lab.su/api/v1/measures/register";
@ -99,9 +98,13 @@ bool sendPayload(MeasureData &data) {
MeasureData data; MeasureData data;
void loop() { void loop() {
data.sensor_id = 0; if (transmissionModule.receive(sensor_id, data)) {
data.sensor_type = 1; data.sensor_id = sensor_id;
data.payload = rand() & 0xffff; data.sensor_type = data.sensor_type;
sendPayload(data); data.payload = data.payload;
delay(5000); 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); cipher->addAuthData(authdata + posn, len);
} }
for (posn = 0; posn < data_size; posn += inc) { cipher->encrypt(buffer + 1, (uint8_t*)&data, data_size);
len = data_size - posn; buffer[0] = data.sensor_id;
if (len > inc)
len = inc;
cipher->encrypt(buffer + posn, (uint8_t*)&data + 1 + posn, len);
}
//************************* //*************************
//Encryption Testing //Encryption Testing
@ -55,10 +51,7 @@ void TransmissionModule::transmit(MeasureData &data)
// Serial.println("works"); // 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]; uint8_t encoded[MSG_LENGTH + ECC_LENGTH];
reedSolomonModule->encode(msg, encoded); reedSolomonModule->encode(buffer, encoded);
transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH); transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH);
} }

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

Loading…
Cancel
Save