Skip to content

Commit

Permalink
0.2.2
Browse files Browse the repository at this point in the history
+ Add delay to GPRS-Examples to make GPRS more stable
+ Cleanup Board examples
  • Loading branch information
holzheu committed Apr 21, 2023
1 parent feb3db0 commit f15bc98
Show file tree
Hide file tree
Showing 31 changed files with 466 additions and 628 deletions.
7 changes: 5 additions & 2 deletions libraries/BayEOSBoards/LowCurrentBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,11 @@ void initLCB() {
pinMode(LED_PIN, OUTPUT);
#endif
#if WITHRAINGAUGE
digitalWrite(2,HIGH); //Enable Pullup on Pin 2 == INT0
attachInterrupt(0,rain_isr,FALLING);
#ifndef RAINGAUGEPIN
#define RAINGAUGEPIN 2
#endif
digitalWrite(RAINGAUGEPIN,HIGH); //Enable Pullup on Pin 2 == INT0
attachInterrupt(digitalPinToInterrupt(RAINGAUGEPIN),rain_isr,FALLING);
rain_count=0;
rain_event=0;
#endif
Expand Down
1 change: 1 addition & 0 deletions libraries/BayEOSBoards/RF24RouterBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ void initLCB() {
blinkLED(2);
adjust_OSCCAL();
#ifdef GPRS_CONFIG
delayLCB(1000);
tx_res = client.begin(38400);
if (! tx_res) myRTC.adjust(client.now());
#else
Expand Down
133 changes: 133 additions & 0 deletions libraries/BayEOSBoards/examples/HX711_ET215/SerialESP/SerialESP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/****************************************************************
Sketch for ESP01 Serial Router connected
to BayEOS Low Power Board via FTDI connection
***************************************************************/
#define ACTION_COUNT 1

#include <RTClib.h>
#include <BayEOSBufferSPIFlash.h>
#include <BayEOS.h>
#include <BaySerial.h>
#include <Sleep.h>

#define ESP01_POWER_PIN 7
#define BOARD_NAME "HX711ESP"
#define POWER_PIN 7
#define BAT_MULTIPLIER 3.3*(100+100)/100/1023
#define ADC_BATPIN A7
// we will collect 60 measurements before we try to send
#define WLAN_SEND_COUNT 10
#define SAMPLING_INT 32

uint16_t wlan_counter = 0;
uint8_t tx_error, res, wlan_status, low_bat = 0;
float bat, tmp_float;
unsigned long last_measurement;

SPIFlash flash(8);
BayEOSBufferSPIFlash myBuffer;
BaySerialESP client(Serial, ESP01_POWER_PIN);

#include <HX711Array.h>
#include <NTC.h>
uint8_t dout[] = { 6 };
uint8_t sck = 3;
long adc[1];
float temp0;

HX711Array scale;
NTC_HX711 ntc(scale, 2 * 470000, 3.0); //adjust resistor values
Scale4PointCal cal0;


#include <LowCurrentBoard.h>


void setup(void) {
initLCB(); //init time2
adjust_OSCCAL();
//CHANGE CONFIG!!
client.begin(38400);
myBuffer.init(flash); //This will restore old pointers
//myBuffer.reset();
client.setBuffer(myBuffer);
myBuffer.setRTC(myRTC, 0); //Nutze RTC relativ!
myBuffer.skip(); //skip the unread frames in Buffer!!
client.powerUp();
while(client.isReady()){
blinkLED(2);
delay(1000);
}
uint8_t res;
while (res = client.setName(BOARD_NAME)) {
if (res == 10 + strlen(BOARD_NAME)) break;
blinkLED(res);
delay(res * 500 + 2000);
}

blinkLED(client.sendMessage("Board started") + 1); client.powerDown();

scale.begin(dout, 1, sck); //start HX711Array with 1 ADCs
cal0.readConf();


startLCB();
wlan_counter = WLAN_SEND_COUNT - 2;
last_measurement = myRTC.now().get();
}

void loop()
{
if (ISSET_ACTION(0)) {
UNSET_ACTION(0);
client.startDataFrame();
client.addChannelValue(millis());
pinMode(POWER_PIN,OUTPUT);
digitalWrite(POWER_PIN,HIGH);
analogReference(DEFAULT);
bat = BAT_MULTIPLIER * analogRead(ADC_BATPIN);
digitalWrite(POWER_PIN,LOW);

client.addChannelValue(bat);
//Some DEBUG values
ntc.readResistance();
temp0 = ntc.getTemp(0);
scale.power_up();
scale.read_average(adc, 2);
scale.read_average(adc);
scale.power_down();
client.addChannelValue(temp0);
client.addChannelValue(adc[0]);
client.addChannelValue(cal0.getWeight(adc[0], temp0));
client.writeToBuffer();
wlan_counter++;

}

if (ISSET_ACTION(7)) {
UNSET_ACTION(7);
if (wlan_counter > WLAN_SEND_COUNT) {
adjust_OSCCAL();
if (! wlan_status) {
client.powerUp();
wlan_status = 1;
}
if (res = client.sendMultiFromBuffer()) tx_error ++;
else tx_error = 0;
blinkLED(res + 1);
if (tx_error > 5 || myBuffer.available() == 0) {
wlan_counter = 0;
wlan_status = 0;
client.powerDown();
tx_error = 0;
}
}
}


sleepLCB();

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void setup()
startLCB(); //some settings and blink three times
client.readConfigFromStringPGM(PSTR(GPRS_CONFIG)); //read GPRS config into RAM
adjust_OSCCAL(); //tune clock of ATMega to make serial communication more stable
delayLCB(1000);
blinkLED(client.begin(38400) + 1); //start the GPRS-Modem (e.g. connect to network)
//one time blinking indicates all ok - more denotes an error. For details look at function definition
delay(2000);
Expand Down Expand Up @@ -83,10 +84,11 @@ void loop() {
if (measurements >= SEND_COUNT & bat_voltage > MIN_VOLTAGE) { //time to send data
digitalWrite(POWER_PIN, HIGH); //power up modem
adjust_OSCCAL();
blinkLED(client.begin(38400) + 1); //connect to network
uint8_t tx_res = 0;
delayLCB(1000);
uint8_t tx_res = client.begin(38400);
blinkLED(tx_res + 1); //connect to network
while (! tx_res && myBuffer.available() && ! ISSET_ACTION(0)) {
tx_res = client.sendMultiFromBuffer(1000); //send 1000 bytes from flash storage
tx_res = client.sendMultiFromBuffer(3000); //send 3000 bytes from flash storage
blinkLED(tx_res + 1);
}
if (! myBuffer.available()) measurements = 0; //all data sent from flash storage
Expand Down
Loading

0 comments on commit f15bc98

Please sign in to comment.