From 214617355993b8330fd61e83505150dac2ac3c6d Mon Sep 17 00:00:00 2001 From: 033zhek <033zhek@gmail.com> Date: Sun, 8 Oct 2023 02:18:20 +0300 Subject: [PATCH] fixed spi-flash-reboot on esp32, encryption kinda works --- .gitignore | 1 + .../TransmissionModule/TransmissionModule.cpp | 36 ++++++++++--------- .../lib/TransmitterModule/TransmitterModule.h | 6 ++-- cybergarden-sensor/src/main.cpp | 9 ++--- 4 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02288c4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +cybergarden-sensor/.vscode diff --git a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp index 2d9b959..2e4e09f 100644 --- a/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp +++ b/cybergarden-sensor/lib/TransmissionModule/TransmissionModule.cpp @@ -30,24 +30,28 @@ void TransmissionModule::encrypt(uint8_t * input_data, size_t data_size, uint8_t cipher->encrypt(buffer + posn, input_data + posn, len); } - byte buffer2[MAX_PLAINTEXT_LEN]; - memset(buffer2, 0xBA, sizeof(buffer)); + //************************* + //Encryption Testing + //************************* - cipher->setKey(encryptionKey, 16); - cipher->setIV(iv, iv_size); + // byte buffer2[MAX_PLAINTEXT_LEN]; + // memset(buffer2, 0xBA, sizeof(buffer)); - for (posn = 0; posn < data_size; posn += inc) { - len = data_size - posn; - if (len > inc) - len = inc; - cipher->decrypt(buffer2 + posn, buffer + posn, len); - } + // cipher->setKey(encryptionKey, 16); + // cipher->setIV(iv, iv_size); - if (memcmp(buffer2, input_data, data_size) != 0) { - // Serial.println("doesn't work"); - } else{ - // Serial.println("works"); - } + // for (posn = 0; posn < data_size; posn += inc) { + // len = data_size - posn; + // if (len > inc) + // len = inc; + // cipher->decrypt(buffer2 + posn, buffer + posn, len); + // } + + // if (memcmp(buffer2, input_data, data_size) != 0) { + // Serial.println("doesn't work"); + // } else{ + // Serial.println("works"); + // } memcpy(output_data, buffer, data_size); } @@ -57,8 +61,6 @@ void TransmissionModule::transmit(MeasureData &data) 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); transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH); diff --git a/cybergarden-sensor/lib/TransmitterModule/TransmitterModule.h b/cybergarden-sensor/lib/TransmitterModule/TransmitterModule.h index b8f6964..94bdae9 100644 --- a/cybergarden-sensor/lib/TransmitterModule/TransmitterModule.h +++ b/cybergarden-sensor/lib/TransmitterModule/TransmitterModule.h @@ -8,15 +8,15 @@ #ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H #define KEMPT_KINKAJOU_TRANSMITTERMODULE_H -#define RH_TRANSMIT_PIN 12 -#define RH_RECEIVE_PIN 11 +#define RH_TRANSMIT_PIN 5 +#define RH_RECEIVE_PIN 4 class TransmitterModule { private: RH_ASK *rhAsk; public: TransmitterModule() { - rhAsk = new RH_ASK(); + rhAsk = new RH_ASK(2000, RH_RECEIVE_PIN, RH_TRANSMIT_PIN); } bool init() { return rhAsk->init(); diff --git a/cybergarden-sensor/src/main.cpp b/cybergarden-sensor/src/main.cpp index 63c7234..508530b 100644 --- a/cybergarden-sensor/src/main.cpp +++ b/cybergarden-sensor/src/main.cpp @@ -10,7 +10,6 @@ TransmissionModule transmissionModule(transmitterModule, reedSolomonModule); void setup() { Serial.begin(115200); transmitterModule.init(); - // pinMode(LED_BUILTIN, OUTPUT); } uint16_t getMockSensorData() { @@ -22,11 +21,7 @@ void loop() { measureData.sensor_id = 0xA5; measureData.sensor_type = 0x01; measureData.payload = getMockSensorData(); - // transmissionModule.encrypt((uint8_t*)&measureData+1, 4, (uint8_t*)&measureData+1); + transmissionModule.encrypt((uint8_t*)&measureData+1, 4, (uint8_t*)&measureData+1); transmissionModule.transmit(measureData); - - // analogWrite(LED_BUILTIN, 255); - // delay(200); - // analogWrite(LED_BUILTIN, 0); - // delay(10000); + delay(1000); } \ No newline at end of file