Skip to content

Commit

Permalink
claim all RFID sensors readings at once, fix bulk claim bug in living…
Browse files Browse the repository at this point in the history
…-room#20

to make the RFID sensor loop faster
  • Loading branch information
jhaip committed Jun 24, 2019
1 parent e6f35bd commit 096529b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
46 changes: 41 additions & 5 deletions src/particle-photon/rfid/src/rfid.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ http_response_t response;

String myID = System.deviceID();

unsigned long lastTime = 0;
unsigned long now = 0;

void publishValueMessage(int sensorId, String sensorValue)
{
char str[300];
Expand All @@ -79,6 +82,28 @@ void publishValueMessage(int sensorId, String sensorValue)
Serial.println(response.status);
}

void publishValueMessages(String sensorValue1, String sensorValue2, String sensorValue3, String sensorValue4, String sensorValue5)
{
char str[300];
sprintf(str, "{\"claim\":[\"Photon%s read \\\"%s\\\" on sensor %i\", \"Photon%s read \\\"%s\\\" on sensor %i\", \"Photon%s read \\\"%s\\\" on sensor %i\", \"Photon%s read \\\"%s\\\" on sensor %i\", \"Photon%s read \\\"%s\\\" on sensor %i\"], \"retract\":\"$ $ Photon%s read $ on sensor $\"}",
(const char *)myID,
sensorValue1.c_str(), 1,
sensorValue2.c_str(), 2,
sensorValue3.c_str(), 3,
sensorValue4.c_str(), 4,
sensorValue5.c_str(), 5,
(const char *)myID);
Serial.println(str);
request.ip = {192, 168, 1, 12};
request.port = 5000;
request.path = "/cleanup-claim";
request.body = str;
Serial.println(request.body);
http.post(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
}

void setup()
{
Serial.begin(9600); // Initialize serial communications with the PC
Expand Down Expand Up @@ -129,19 +154,30 @@ String check_reader(MFRC522 reader)

void loop()
{

delay(50);

lastTime = millis();

String val_a = check_reader(mfrc522);
String val_b = check_reader(mfrc522_b);
String val_c = check_reader(mfrc522_c);
String val_d = check_reader(mfrc522_d);
String val_e = check_reader(mfrc522_e);
// String val_f = check_reader(mfrc522_f);

publishValueMessage(1, val_a);
publishValueMessage(2, val_b);
publishValueMessage(3, val_c);
publishValueMessage(4, val_d);
publishValueMessage(5, val_e);
now = millis();
Serial.printlnf("rfid read lag: %lu ms", (now - lastTime));
lastTime = millis();

publishValueMessages(val_a, val_b, val_c, val_d, val_e);
// publishValueMessage(1, val_a);
// publishValueMessage(2, val_b);
// publishValueMessage(3, val_c);
// publishValueMessage(4, val_d);
// publishValueMessage(5, val_e);
// publishValueMessage(6, val_f);

now = millis();
Serial.printlnf("send lag: %lu ms", (now-lastTime));
}
8 changes: 6 additions & 2 deletions src/standalone_processes/20__httpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ app.post('/cleanup-claim', (req, res) => {
console.error("cleanup-claim")
console.error(req.body)
if (Array.isArray(req.body.retract)) {
room.retractRaw(...req.body.retract)
req.body.retract.forEach(retraction => {
room.retractRaw(retraction)
})
} else {
room.retractRaw(req.body.retract)
}
if (Array.isArray(req.body.claim)) {
room.assert(...req.body.claim)
req.body.claim.forEach(claim => {
room.assert(claim)
})
} else {
room.assert(req.body.claim)
}
Expand Down

0 comments on commit 096529b

Please sign in to comment.