Skip to content

Conversation

Hellebore
Copy link

@Hellebore Hellebore commented May 2, 2025

Summary by Sourcery

Implement analytics API and hardware sensor communication system for environmental monitoring

New Features:

  • Add Firebase Admin integration for fetching analytics data
  • Create LoRa-based hardware sensor communication system

Enhancements:

  • Implement server-side data retrieval from Firestore
  • Add hardware-side sensor data transmission and power management

Deployment:

  • Configure Firebase Admin credentials for server-side interactions

Chores:

  • Add firebase-admin package to project dependencies

xkaze09 added 11 commits April 29, 2025 20:25
- Added firebase-admin version 13.3.0 to package.json and package-lock.json
- Updated various dependencies in package-lock.json for improved stability and performance
- Add a new GET method in route.ts to fetch sensor readings from Firestore
- Return the latest 500 readings in JSON format, handling errors appropriately
- Ensure Firestore query is optimized with index usage
- Create a new file for Firebase admin setup
- Configure Firebase admin with environment variables for secure access
- Initialize Firestore database for backend interactions
- Add a new receiver.ino file for handling LoRa data reception
- Implement AES decryption for incoming payloads
- Set up Wi-Fi, Firebase, and NTP client for data synchronization
- Parse received LoRa data and upload sensor readings to Firebase
- Update OLED display with temperature, humidity, and heat index values
- Replace the previous AES decryption implementation with a more efficient version
- Update the parsing logic for decrypted data from LoRa
- Dynamically set the STATION_ID based on the device's MAC address
- Clean up unused functions and improve code organization for better readability
- Implemented REAL TIME functionality to update the Realtime Database with temperature, humidity, heat index, and timestamp data
…irebase integration

- Removed AES decryption for incoming LoRa data, simplifying the payload handling process. Will add later
- Updated parsing logic to directly process received payloads
- Enhanced Firebase Firestore document creation with clearer collection management
- Cleaned up unused code and improved overall readability
…updates

- Introduced RECEIVER_ID based on the device's MAC address for better identification
- Updated Firebase Firestore and Realtime Database interactions to include receiver ID
- Cleared sensitive information from the configuration for security purposes
SEAN:
- Implemented a new sender.ino file to handle LoRa data transmission
- Integrated DHT sensor for temperature and humidity readings
- Added relay control for power management based on sensor data
- Established LoRa communication setup with configurable frequency and sync word
…n LoRa sender

- Added WiFi library to obtain MAC address for unique sensor identification
- Initialized SENSOR_ID based on the device's MAC address
- Enhanced error handling for DHT sensor readings
- Cleaned up code formatting and improved readability
…and sender

- Removed unnecessary emoji from comments for clarity
- Enhanced formatting and spacing in sender.ino for better readability
- Streamlined comment structure in receiver.ino to maintain consistency
@Hellebore
Copy link
Author

This is a benchmark review for experiment bakeoff.
Run ID: bakeoff/benchmark_2025-05-02T11-38-04_v1-36-0-dirty.

This pull request was cloned from https://github.com/tinapayy/B-1N1T/pull/36. (Note: the URL is not a link to avoid triggering a notification on the original pull request.)

Experiment configuration
review_config:
  # User configuration for the review
  # - benchmark - use the user config from the benchmark reviews
  # - <value> - use the value directly
  user_review_config:
    enable_ai_review: true
    enable_rule_comments: false

    enable_complexity_comments: benchmark
    enable_security_comments: benchmark
    enable_tests_comments: benchmark
    enable_comment_suggestions: benchmark

    enable_pull_request_summary: benchmark
    enable_review_guide: benchmark

    enable_approvals: false
    base_branches: [base-sha.*]

  ai_review_config:
    # The model responses to use for the experiment
    # - benchmark - use the model responses from the benchmark reviews
    # - llm - call the language model to generate responses
    model_responses:
      comments_model: benchmark
      comment_validation_model: benchmark
      comment_suggestion_model: benchmark
      complexity_model: benchmark
      security_model: benchmark
      tests_model: benchmark
      pull_request_summary_model: benchmark
      review_guide_model: benchmark
      overall_comments_model: benchmark

# The pull request dataset to run the experiment on
pull_request_dataset:
# CodeRabbit
- https://github.com/neerajkumar161/node-coveralls-integration/pull/5
- https://github.com/gunner95/vertx-rest/pull/1
- https://github.com/Altinn/altinn-access-management-frontend/pull/1427
- https://github.com/theMr17/github-notifier/pull/14
- https://github.com/bearycool11/AI_memory_Loops/pull/142

# Greptile
- https://github.com/gumloop/guMCP/pull/119
- https://github.com/autoblocksai/python-sdk/pull/335
- https://github.com/grepdemos/ImageSharp/pull/6
- https://github.com/grepdemos/server/pull/61
- https://github.com/websentry-ai/pipelines/pull/25

# Graphite
- https://github.com/KittyCAD/modeling-app/pull/6648
- https://github.com/KittyCAD/modeling-app/pull/6628
- https://github.com/Varedis-Org/AI-Test-Repo/pull/2
- https://github.com/deeep-network/bedrock/pull/198
- https://github.com/Metta-AI/metta/pull/277

# Copilot
- https://github.com/hmcts/rpx-xui-webapp/pull/4438
- https://github.com/ganchdev/quez/pull/104
- https://github.com/xbcsmith/ymlfxr/pull/13
- https://github.com/tinapayy/B-1N1T/pull/36
- https://github.com/coder/devcontainer-features/pull/6

# Questions to ask to label the review comments
review_comment_labels: []
# - label: correct
#   question: Is this comment correct?

# Benchmark reviews generated by running
#   python -m scripts.experiment benchmark <experiment_name>
benchmark_reviews: []

@Hellebore
Copy link
Author

Reviewer's Guide

This pull request introduces Arduino firmware for LoRa-based sensor data collection and a Next.js API endpoint to retrieve this data. The receiver firmware uploads sensor readings (temperature, humidity, heat index) received via LoRa to Firestore and Firebase RTDB. The new API route /api/analytics/fetch uses the firebase-admin SDK to query Firestore for the latest readings.

File-Level Changes

Change Details Files
Added Arduino firmware for LoRa sensor network.
  • Implemented LoRa sender (sender.ino) to read DHT sensor data and transmit.
  • Implemented LoRa receiver (receiver.ino) to receive data, connect to WiFi, and upload to Firestore and RTDB.
  • Included NTP time synchronization and OLED display updates on the receiver.
  • Added relay switching logic to the sender for potential power management.
hardware/receiver.ino
hardware/sender.ino
Integrated Firebase Admin SDK and created an API endpoint for analytics.
  • Added firebase-admin dependency.
  • Created firebase-admin.ts to initialize the Admin SDK.
  • Implemented GET API route /api/analytics/fetch to query the latest sensor readings from Firestore using a collection group query.
bantay-init/package.json
bantay-init/package-lock.json
bantay-init/src/lib/firebase-admin.ts
bantay-init/src/app/api/analytics/fetch/route.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Author

@Hellebore Hellebore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Hellebore - I've reviewed your changes - here's some feedback:

  • Consider moving sensitive credentials like WiFi passwords and Firebase keys out of the receiver.ino source code, perhaps using a configuration file or environment variables during flashing.
  • Firebase Admin credentials should remain server-side only; avoid using the NEXT_PUBLIC_ prefix for these environment variables in firebase-admin.ts.
  • The analytics API route fetches a fixed number of 500 readings; consider adding parameters for pagination or filtering if the frontend might need more specific data subsets.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

LangSmith trace

Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

timeClient.update();
}

void parsePlainPayload(String payload) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Improve string parsing reliability in parsePlainPayload.

Use a dedicated split method or explicitly validate each token before converting to float to handle malformed or extra delimiters.

Suggested implementation:

#include <stdlib.h>

// Helper function to validate if a string is a valid float number.
bool isValidFloat(String s) {
  // Convert String to a C string then use strtof to check conversion.
  char buf[s.length() + 1];
  s.toCharArray(buf, s.length() + 1);
  char *end;
  strtof(buf, &end);
  return (*end == '\0');
}

// Helper function to split a string by a given delimiter.
// Returns the number of tokens found.
int splitString(String str, char delimiter, String tokens[], int maxTokens) {
  int tokenCount = 0;
  int pos = 0;
  int index = 0;
  while ((pos = str.indexOf(delimiter)) != -1 && tokenCount < maxTokens) {
    tokens[tokenCount++] = str.substring(0, pos);
    str = str.substring(pos + 1);
  }
  // Add the last token if any and if there's room.
  if (tokenCount < maxTokens) {
    tokens[tokenCount++] = str;
  }
  return tokenCount;
}

void parsePlainPayload(String payload) {
  String data[3];
  int count = splitString(payload, ';', data, 3);

  // Validate each token before converting to float.
  if (count >= 1 && isValidFloat(data[0])) {
    temperature = data[0].toFloat();
  } else {
    temperature = 0.0; // Default value or error handling
  }
  if (count >= 2 && isValidFloat(data[1])) {
    humidity = data[1].toFloat();
  } else {
    humidity = 0.0; // Default value or error handling
  }

Ensure to adjust any references to variables (like "temperature" and "humidity") if needed, and include necessary error handling or logging mechanisms according to your project's standards.

unsigned long relayInterval = 10UL * 1000UL; // 60 seconds in milliseconds
bool useInitialPowerbank = true;

void startDHT()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Clarify the purpose of startDHT.

Since it only checks sensor readings and logs failures rather than initializing, consider renaming it to verifyDHT for clarity.

Suggested implementation:

void verifyDHT()

  Serial.println("DHT sensor check successful!");

If there are any calls to startDHT() elsewhere in the code, please update them to call verifyDHT() instead.

Comment on lines +33 to +42
unsigned long relayInterval = 10UL * 1000UL; // 60 seconds in milliseconds
bool useInitialPowerbank = true;

void startDHT()
{
if (isnan(humidity) || isnan(temperature))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Clarify relayInterval values.

Please clarify why relayInterval starts at 10 s but then switches to 60 s after the first relay by adding an explanatory comment.

Comment on lines +5 to +9
credential: cert({
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
clientEmail: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_EMAIL,
privateKey: process.env.NEXT_PUBLIC_FIREBASE_PRIVATE_KEY?.replace(/\\n/g, "\n"),
}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Use non-public env vars for firebase admin credentials.

NEXT_PUBLIC_ vars are exposed to the client. Use private (non-client-accessible) env vars for firebase-admin credentials to keep them secure.

Suggested change
credential: cert({
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
clientEmail: process.env.NEXT_PUBLIC_FIREBASE_CLIENT_EMAIL,
privateKey: process.env.NEXT_PUBLIC_FIREBASE_PRIVATE_KEY?.replace(/\\n/g, "\n"),
}),
credential: cert({
projectId: process.env.FIREBASE_PROJECT_ID,
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
privateKey: process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/g, "\n"),
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants