Skip to content

Commit

Permalink
Merge pull request #114 from SpartanWorks/fix-ns-binding-error
Browse files Browse the repository at this point in the history
Fixes NS binding errors stemming from way too long request processing.
  • Loading branch information
Idorobots authored Dec 24, 2023
2 parents 97a435e + 32a9e0e commit 4e50c1c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion device/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lib_deps =
adafruit/Adafruit BMP280 Library@2.6.6
sparkfun/SparkFun CCS811 Arduino Library@2.0.3
milesburton/DallasTemperature@3.11.0
sparkfun/SparkFun HTU21D Humidity and Temperature Sensor Breakout@1.1.3
https://github.com/adafruit/Adafruit_HTU21DF_Library@1.1.2
wifwaf/MH-Z19@1.5.4
https://github.com/arduino-libraries/Arduino_JSON@0.2.0
https://github.com/adafruit/DHT-sensor-library@1.4.6
Expand Down
3 changes: 2 additions & 1 deletion device/src/APIServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ void streamJSON(WiFiClient& client, JSONVar& json) {
int len = json.length();
for (uint16_t i = 0; i < len; i++) {
JSONVar value = json[i];
streamJSON(client, value);
// NOTE Assumes that these will be small enough to fit in RAM one at one time.
client.write(JSON.stringify(value).c_str());

if (i < len - 1) {
client.write(",");
Expand Down
2 changes: 1 addition & 1 deletion device/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void setup(void){
// API
APIServer *server = new APIServer(ssn.device(), ssn.log(), FSImplementation);
server->begin();
ssn.scheduler().spawn("handle API", 110, [server](Task *t) {
ssn.scheduler().spawn("handle API", 100, [server](Task *t) {
server->handleClient();
});

Expand Down
14 changes: 6 additions & 8 deletions device/src/sensors/HTU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HTU::HTU(TwoWire *i2c, uint8_t addr, uint16_t interval):
i2c(i2c),
address(addr),
sensor(HTU21D()),
sensor(Adafruit_HTU21DF()),
sampleInterval(interval),
humidity(nullptr),
temperature(nullptr),
Expand Down Expand Up @@ -46,7 +46,7 @@ HTU* HTU::create(JSONVar &config) {
}

void HTU::begin(System &system) {
this->sensor.begin(*(this->i2c));
this->sensor.begin(this->i2c);

system.device().attach(this);

Expand All @@ -62,7 +62,7 @@ void HTU::update() {

if (this->humidity != nullptr) {
hum = this->sensor.readHumidity();
if (hum == ERROR_I2C_TIMEOUT || hum == ERROR_BAD_CRC) {
if (hum == NAN) {
this->humidity->setError(String("Could not read sensor. Response: ") + String(hum));
} else {
this->humidity->add(hum);
Expand All @@ -73,19 +73,17 @@ void HTU::update() {

if (this->temperature != nullptr) {
temp = this->sensor.readTemperature();
if (temp == ERROR_I2C_TIMEOUT || temp == ERROR_BAD_CRC) {
if (temp == NAN) {
this->temperature->setError(String("Could not read sensor. Response: ") + String(temp));
} else {
this->temperature->add(temp);
}
}

if (this->temperature != nullptr
&& temp != ERROR_I2C_TIMEOUT
&& temp != ERROR_BAD_CRC
&& temp != NAN
&& this->humidity != nullptr
&& hum != ERROR_I2C_TIMEOUT
&& hum != ERROR_BAD_CRC) {
&& hum != NAN) {
foreach<Sensor*>(this->toCompensate, [=](Sensor *s) {
s->setCompensationParameters(temp, hum);
});
Expand Down
4 changes: 2 additions & 2 deletions device/src/sensors/HTU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define __HTU_HPP__

#include <Wire.h>
#include <SparkFunHTU21D.h>
#include <Adafruit_HTU21DF.h>
#include "System.hpp"

class HTU: public Sensor {
private:
TwoWire *i2c;
uint8_t address;
HTU21D sensor;
Adafruit_HTU21DF sensor;
uint16_t sampleInterval;
Reading<float> *humidity;
Reading<float> *temperature;
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/services/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface UpdateCallback {
(arg: DeviceData): void;
}

const TIMEOUT = 2000;
const TIMEOUT = 5000;

export class DeviceService {
baseUrl: string;
Expand Down

0 comments on commit 4e50c1c

Please sign in to comment.