fixed spi-flash-reboot on esp32, encryption kinda works

pull/1/head
033zhek 1 year ago
parent 8cb54166b9
commit 2146173559

1
.gitignore vendored

@ -0,0 +1 @@
cybergarden-sensor/.vscode

@ -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); cipher->encrypt(buffer + posn, input_data + posn, len);
} }
byte buffer2[MAX_PLAINTEXT_LEN]; //*************************
memset(buffer2, 0xBA, sizeof(buffer)); //Encryption Testing
//*************************
cipher->setKey(encryptionKey, 16); // byte buffer2[MAX_PLAINTEXT_LEN];
cipher->setIV(iv, iv_size); // memset(buffer2, 0xBA, sizeof(buffer));
for (posn = 0; posn < data_size; posn += inc) { // cipher->setKey(encryptionKey, 16);
len = data_size - posn; // cipher->setIV(iv, iv_size);
if (len > inc)
len = inc; // for (posn = 0; posn < data_size; posn += inc) {
cipher->decrypt(buffer2 + posn, buffer + posn, len); // len = data_size - posn;
} // if (len > inc)
// len = inc;
// cipher->decrypt(buffer2 + posn, buffer + posn, len);
// }
if (memcmp(buffer2, input_data, data_size) != 0) { // if (memcmp(buffer2, input_data, data_size) != 0) {
// Serial.println("doesn't work"); // Serial.println("doesn't work");
} else{ // } else{
// Serial.println("works"); // Serial.println("works");
} // }
memcpy(output_data, buffer, data_size); memcpy(output_data, buffer, data_size);
} }
@ -57,8 +61,6 @@ void TransmissionModule::transmit(MeasureData &data)
uint8_t msg[MSG_LENGTH]; uint8_t msg[MSG_LENGTH];
msg[0] = data.sensor_id; msg[0] = data.sensor_id;
memcpy(msg + 1, (void *) &data, 4); 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(msg, encoded);
transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH); transmitterModule->send(encoded, MSG_LENGTH + ECC_LENGTH);

@ -8,15 +8,15 @@
#ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H #ifndef KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define KEMPT_KINKAJOU_TRANSMITTERMODULE_H #define KEMPT_KINKAJOU_TRANSMITTERMODULE_H
#define RH_TRANSMIT_PIN 12 #define RH_TRANSMIT_PIN 5
#define RH_RECEIVE_PIN 11 #define RH_RECEIVE_PIN 4
class TransmitterModule { class TransmitterModule {
private: private:
RH_ASK *rhAsk; RH_ASK *rhAsk;
public: public:
TransmitterModule() { TransmitterModule() {
rhAsk = new RH_ASK(); rhAsk = new RH_ASK(2000, RH_RECEIVE_PIN, RH_TRANSMIT_PIN);
} }
bool init() { bool init() {
return rhAsk->init(); return rhAsk->init();

@ -10,7 +10,6 @@ TransmissionModule transmissionModule(transmitterModule, reedSolomonModule);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
transmitterModule.init(); transmitterModule.init();
// pinMode(LED_BUILTIN, OUTPUT);
} }
uint16_t getMockSensorData() { uint16_t getMockSensorData() {
@ -22,11 +21,7 @@ void loop() {
measureData.sensor_id = 0xA5; measureData.sensor_id = 0xA5;
measureData.sensor_type = 0x01; measureData.sensor_type = 0x01;
measureData.payload = getMockSensorData(); 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); transmissionModule.transmit(measureData);
delay(1000);
// analogWrite(LED_BUILTIN, 255);
// delay(200);
// analogWrite(LED_BUILTIN, 0);
// delay(10000);
} }
Loading…
Cancel
Save