OPEnSLab-OSU / Spool

GNU General Public License v3.0
2 stars 1 forks source link

Overwritten Modules with Same Key #14

Closed smitmad9 closed 4 years ago

smitmad9 commented 4 years ago

Describe the bug When there are different modules (Ex. X_Location, Y_Location, Z_Location) with the same data key (Ex. MM), only the final module's data is displayed on the front-end because the others are overwritten.

Expected behavior Every module's should display data for each key-value pair. (Ex. MM should be displayed for X_Location, Y_Location, and Z_Location).

Hardware in Use EthernetWing and M0 Feather Board with LoRa.

To Reproduce

  1. Set up eGreenhouse for data logging to Spool (in production).
  2. Open the Hub_Recieve.ino sketch in the Arduino IDE.
  3. Edit the config.h file in Loom to include the device's configurator_id, device_id, and default spool domain & data endpoint.
  4. Compile the sketch to log data.
  5. Log in to Spool, Dashboard -> Networks -> Devices -> View data.

Screenshots Overwrite

Desktop (please complete the following information):

Code In the Arduino IDE while editing the main.ino, go to 'Edit' -> 'Copy as HTML' and paste the output of that here. (Note: To test the full code: please checkout here: code

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This is the Hub_Receive for eGreenhouse.
// It will receive package from Sensor Package to publish to GoogleSheets.
//
// If you want to checkout the GoogleSheets, find the link below
// https://docs.google.com/spreadsheets/d/1M0TS0sN5z6AMDMXzh-0gRyxqf6c6dWQTrbkpmNTeRXI/edit#gid=0
//
// Author: Kenneth Kang
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <Loom.h>                                                                   // Need to include the Loom Package into the program
#include <ArduinoJson.h>                                                            // Need to include for the JsonDocument

#include "eGreenhouseJSON.h"                                                        // Include the JSON Package constructor

const char* json_config =                                                           // Include Configuration
#include "config.h"
;

int checker;                                                                        // Initialize checker

LoomFactory<
  Enable::Internet::All,                                                            // For GoogleSheet in Wifi/Ethernet,we need to enabled it
  Enable::Sensors::Disabled,                                                        // For getting sensor data: We don't need it for this program
  Enable::Radios::Enabled,                                                          // For Communcation between boards
  Enable::Actuators::Disabled,                                                      // For Motors (It will be part in the Hyperdrive)
  Enable::Max::Disabled                                                             // Never ever Enable this part: It will kill the program
> ModuleFactory{};

LoomManager Loom{ &ModuleFactory };                                                 // Having all of the properties of LoomFactory<> in a manager called Loom

void setup() {                                                                      // Put your setup code here, to run once:
  Loom.begin_serial(true);                                                          // Starting Loom
  Loom.parse_config(json_config);                                                   // Getting Information in Config.h file
  Loom.print_config();                                                              // Printing out the config.h information to make sure it is running correctly or not

  LPrintln("\n ** Hub Ready ** ");                                                  // Indicating the user that setup function is complete

}

void loop() {                                                                       // Put your main code here, to run repeatedly:
    eGreenhouse_Base in_data;                                                       // Create a new struct to convert back JSON
    if(Loom.LoRa().receive_blocking_raw(in_data.raw, sizeof(in_data.raw), 30000)){  // Wait the package from the Sensor Package for 30 seconds. If not then it will not be publish
      JsonObject internal_json = Loom.internal_json(true);                          // Create a new JSON
      struct_to_json(in_data, internal_json);                                       // Convert incoming struct to JSON
      Loom.display_data();                                                          // Display printed new JSON formatted data on serial monitor to double check 
      const JsonObject complete_json = Loom.internal_json(false);                   // Open the JSON from code
      const JsonArray contents = complete_json["contents"];                         // For simple syntax use
      checker = contents[7]["data"]["Bool"];                                        // Update the checker value
      if(checker == 1){                                                             // If the checker value is equal to 1(It tells that it came from the eGreenhouse_Sensor_Package)
        Loom.GoogleSheets().publish();                                              // It will publish the data into GoogleSheets: check the the link in line 7
      }
      else{
        LPrintln("Failed to Publish to GoogleSheets");                              // Else, it will print this statement
      }
   }
}

Config In the Arduino IDE while editing the config.json, go to 'Edit' -> 'Copy for HTML' and paste the output of that here.

{\
  'general':{'name':'eGH_Hub_Receive', 'instance':1,'interval':5000},\
  'components':[\
    {'name':'Ethernet','params':['Ether1',[152,118,182,16,97,214],[192,168,0,1]]},\
    {'name':'Spool', 'params':['Spool1', 7001, '5f32f5ec740dc0000803d001','5f32f5ec740dc0000803d001', '101',\
      '-----BEGIN CERTIFICATE-----\nMIICDDCCAbKgAwIBAgIJALiC/NTuve9DMAoGCCqGSM49BAMCMIGCMQswCQYDVQQG\nEwJVUzELMAkGA1UECAwCT1IxEjAQBgNVBAcMCUNvcnZhbGxpczESMBAGA1UECgwJ\nT1BFblMgTGFiMR0wGwYDVQQLDBRTcG9vbCBEZXZpY2UgUm9vdCBDQTEfMB0GA1UE\nAwwWc3Bvb2wub3Blbi1zZW5zaW5nLm9yZzAeFw0yMDA4MTExOTQ3NTZaFw0yMTAy\nMjcxOTQ3NTZaMFAxCzAJBgNVBAYTAlVTMQ8wDQYDVQQIDAZPcmVnb24xGTAXBgNV\nBAoMEE9wZW4gU2Vuc2luZyBMYWIxFTATBgNVBAMMDFNwb29sIENsaWVudDBZMBMG\nByqGSM49AgEGCCqGSM49AwEHA0IABGH6B9mePQhOr2en5NvR2IIXRWx3tf2bnxyY\nlLVkRvt2WW4uSuJW3DgQYznysQ5tt7UYl0HIJYUEAhB7R0N7EG6jQjBAMB0GA1Ud\nDgQWBBSeypvQioykra7fDN9UrjwJjhoC5zAfBgNVHSMEGDAWgBSF4x4mpv2TGR8a\nE/mvYBdcT3ykxjAKBggqhkjOPQQDAgNIADBFAiEAuJh5Ea+EX93zX+fz0BaYM+3E\nVAJq9mDphKtJAWIV8hUCICmKrT3Jw/GeUIkcvkjbTpxpYbwLaYCJlffQ4UBA2R3U\n-----END CERTIFICATE-----\n',\
      '-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIP0r+DFBE4zjaGctTaTNeabeOIE9ILZprE+/F0V47XfJoAoGCCqGSM49\nAwEHoUQDQgAEYfoH2Z49CE6vZ6fk29HYghdFbHe1/ZufHJiUtWRG+3ZZbi5K4lbc\nOBBjOfKxDm23tRiXQcglhQQCEHtHQ3sQbg==\n-----END EC PRIVATE KEY-----\n',\
      'device.open-sensing.org','/api/device/data']},\
    {'name':'LoRa','params':[255,12,23,3,200]}\
  ]\
}

Additional context Add any other context about the problem here.

smitmad9 commented 4 years ago

Fixed by concatenating the module name with the key name. Here is an example of duplicate keys (MM) with X, Y, and Z locations. Now all three data points are recorded.

Screen Shot 2020-08-15 at 4 18 35 PM