Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arbeeno #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ For bee industry researchers who need to detect hive disease the Connected Hive
Unlike existing ad hoc hive metering and observations the Connected Hive:
* provides access to a large repository of near real-time data
* supports development of advanced and novel sensors

2018
71 changes: 37 additions & 34 deletions src/Arbeeno/Arbeeno.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include <SoftwareSerial.h>
//#include <SoftwareSerial.h>
#include <TinyGPS.h>
//#include <Seeed_BME280.h>
#include "BME280.h"
#include "ReadSensors.h"

TinyGPS gps;
SoftwareSerial ss(3, 4); // Arduino TX, RX ,
//TinyGPS gps;
//SoftwareSerial ss(3, 4); // Arduino TX, RX ,


//VARIABLES ---------------------------------------------------------------------------------------

static void smartdelay(unsigned long ms);
int delayMilli = 10000;
//static void smartdelay(unsigned long ms);
static void print_float(float val, float invalid, int len, int prec);
static void print_int(unsigned long val, unsigned long invalid, int len);
static void print_date(TinyGPS &gps);
//static void print_date(TinyGPS &gps);
static void print_str(const char *str, int len);
float flat, flon;
BME280 bmeInternal;
Expand All @@ -40,6 +41,7 @@ char flatStr[12];
char flonStr[12];



#if !defined(DISABLE_INVERT_IQ_ON_RX)
#error This example requires DISABLE_INVERT_IQ_ON_RX to be set. Update \
config.h in the lmic library to set it.
Expand Down Expand Up @@ -89,7 +91,7 @@ void setup() {

// initialize both serial ports:
Serial.begin(9600); // Serial to print out GPS info in Arduino IDE
ss.begin(9600); // SoftSerial port to get GPS data.
//ss.begin(9600); // SoftSerial port to get GPS data.
Serial.println("Starting");
#ifdef VCC_ENABLE
// For Pinoccio Scout boards
Expand Down Expand Up @@ -132,12 +134,12 @@ void loop() {
unsigned short sentences = 0, failed = 0;
// static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

gps.f_get_position(&flat, &flon, &age);
print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
Serial.println();
// gps.f_get_position(&flat, &flon, &age);
//print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
//print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6);
//Serial.println();

smartdelay(1000);
delay(delayMilli);
}

//---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -183,30 +185,30 @@ static void txdone_func (osjob_t* job) {

static void tx_func (osjob_t* job) {

char gpsBuffer[40+1];
strcpy(gpsBuffer, "");
// char gpsBuffer[40+1];
// strcpy(gpsBuffer, "");
char bufferStr[110];
char* sensors;
sensors = getSensorData(bmeInternal, bmeExternal);

if (flat != TinyGPS::GPS_INVALID_F_ANGLE && flon != TinyGPS::GPS_INVALID_F_ANGLE)
{
//if (flat != TinyGPS::GPS_INVALID_F_ANGLE && flon != TinyGPS::GPS_INVALID_F_ANGLE)
// {
//strcpy(gpsBuffer, "");
dtostrf(flat, 12, 6, flatStr);
dtostrf(flon, 12, 6, flonStr);
}
else
{
strcpy(flatStr, "*");
strcpy(flonStr, "*");
}
// dtostrf(flat, 12, 6, flatStr);
// dtostrf(flon, 12, 6, flonStr);
// }
// else
// {
// strcpy(flatStr, "*");
// strcpy(flonStr, "*");
// }


sprintf (bufferStr, "%s,%s,%s", sensors, flatStr, flonStr);
//sprintf (bufferStr, "%s,%s,%s", sensors, flatStr, flonStr);
//sprintf (bufferStr, "%s,%s,%s", sensors, flat, flon);
//sprintf (bufferStr, "%s-%s~%d", sensors, gpsBuffer);
Serial.println(bufferStr);
tx(bufferStr, txdone_func);
Serial.println(sensors);
tx(sensors, txdone_func);

// reschedule job every TX_INTERVAL (plus a bit of random to prevent
// systematic collisions), unless packets are received, then rx_func
Expand Down Expand Up @@ -238,15 +240,16 @@ static void print_float(float val, float invalid, int len, int prec)
//---------------------------------------------------------------------------------------
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
{

//unsigned long start = millis();
//do
//{
// while (ss.available())
// {
//ss.print(Serial.read());
gps.encode(ss.read());
}
} while (millis() - start < ms);
// gps.encode(ss.read());
// }
//} while (millis() - start < ms);
}

//---------------------------------------------------------------------------------------
Expand Down
16 changes: 14 additions & 2 deletions src/Arbeeno/ReadSensors.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include <Wire.h>
#include "BME280.h"
#include "Arduino.h"
//https://github.com/queuetue/Q2-HX711-Arduino-Library
#include <Q2HX711.h>

//BME280 bmeInternal;
//BME280 bmeExternal;

//scales
const byte hx711_data_pin = A2;
const byte hx711_clock_pin = A3;
Q2HX711 hx711(hx711_data_pin, hx711_clock_pin);

char _deviceId[] = "00001";
int _loopDelay = 10000;

Expand Down Expand Up @@ -46,8 +53,13 @@ char* getSensorData(BME280 bmeInternal, BME280 bmeExternal)
// Loudness
_loudness = analogRead(0);

// Weight - mocked due to additional hardware requirements
dtostrf(22.72, 5, 2, _weightStr);
// Weight
double scale_read = hx711.read()/100.0;
//Serial.println(scale_read);
double scale_diff = scale_read - 85850; //tare weight
double kg = scale_diff * 0.004; // convert to kg
//Serial.println(kg);
dtostrf(kg, 5, 2, _weightStr);

sprintf(_bufferStr, "%s,%s,%s,%s,%s,%s,%s,%s,%d", _deviceId, _tempIntStr, _pressureIntStr, _humidIntStr, _tempExtStr, _pressureExtStr, _humidExtStr, _weightStr, _loudness);

Expand Down