Replies: 4 comments 4 replies
-
Thanks a lot, Håkan! It's great to see you're using controllers. What you'd like is possible, as long as you convert your 16 bit binary number into an 16 bit unsigned integer. This is actually getting in to an area of FDRS that needs improvement: So, what this means in this case is that a binary number like 1110011001100101 will be converted to 16-bit integer So all of that is to say that yes, you can represent binary with a float just fine, but be careful if going above 16 bits. I think adding a datatype for 16-bit binary data would be okay, but fixing the system to allow up to the full 32 bits would be better. I'm going to leave #187 open as a reminder, and I'll use it as a planning point for how to implement the fix. My current favorite idea is to split the 256 datatypes into two, and make the first 128 floats, and the second half integers. So, for example, type 129 would indicate a binary temperature (where type 1 is float temperature). |
Beta Was this translation helpful? Give feedback.
-
Works fine using a 16 bit unsigned integer!. Need to tidy up code when finishing though. It's perfectly ok for now but in future it would be nice to be able to send both float's and integers as you mentioned. And the possibility to send plain text would also be on my wishlist. `/* */ #include <fdrs_node.h> Adafruit_MCP23X17 mcp; // for debug only //only send if value have changed not to stress system, causes TIMEOUT !!!! //############################## } beginFDRS(); mcp.begin_I2C(); } } loopFDRS(); if (currentMillis - previousMillis >= interval) { //send data // DBG(sendFDRS());
}//end if currentmillis... I have one small issue,not a critical one but when I'm in code only want the node to send only if a value has changed (to minimize unessasary traffic) it times out and will not recover unless rebooted. Is it mandatory to use the sleepFDRS function? I have commented out this since this node will never sleep BTW the <> (code insert) doesn't seem to work or I make som stupid mistake that's why it looks so messy. |
Beta Was this translation helpful? Give feedback.
-
To add a block of code put three accent symbols above and below it: " ``` "
To make it look fancy, have the first one say "``` cpp" void setup() {
pinMode(status_PIN, OUTPUT);//visualizing node ok
beginFDRS();
if (addFDRS(1000, fdrs_recv_cb))
subscribeFDRS(READING_ID);
Wire.begin(); // I/O expander
mcp.begin_I2C();
//set all pins to output
for (int i = 0; i <= 15; i++) {
mcp.pinMode(i, OUTPUT);
}
} You might also want to try the "Auto Format" feature in Arduino IDE to help clean up your code. You are not required to use sleepFDRS(). |
Beta Was this translation helpful? Give feedback.
-
There are many implementations of data serialization formats. |
Beta Was this translation helpful? Give feedback.
-
Hi!
I have tried a number of 'mesh' like system but mostly fails due to short distance,instability ets. Stumbled over FDRS and it looks awesome! I have set up a basic scenario with one gateway and two ESPnow node's sofar and worked more or less out of the box. I'm working on a node using MCP23017 for easy managing up to 16 relays with one cmd. It would be nice if you could send a text string. In my case I want to send a string like "1110011001100101" showing status of all relays for further processing (Home Assistant). It could also be nice with a text string that could send alerts etc. My working but not finished code looks like this ;
/*
MCP23017 uses inverted logic. Output from 0 to 15
To set relay no 12 to ON for example send:
[{"id":31,"type":0,"data":120}] //set to on
[{"id":31,"type":0,"data":121}]//set to off
*/
#define FDRS_DEBUG
#define READING_ID 31
#define GTWY_MAC 0x01
#define USE_ESPNOW
#define COIL_PIN LED_BUILTIN
#include <fdrs_node.h>
#include <Adafruit_MCP23X17.h>
Adafruit_MCP23X17 mcp;
// relay var's
int tmpdata = 0;
int relayno = 0;
int relay_status = 0;
//########## Non blocking delay #
unsigned long previousMillis = 0;
const long interval = 2000;
int previousValue = 0;
int currentValue = 0;
//##############################
void fdrs_recv_cb(DataReading theData) {
tmpdata = (int)theData.d;
}
void setup() {
beginFDRS();
if (addFDRS(1000, fdrs_recv_cb))
subscribeFDRS(READING_ID);
mcp.begin_I2C();
//set all pins to output
for (int i = 0; i <= 255; i++) {
mcp.pinMode(i, OUTPUT);
}
}
void loop() {
unsigned long currentMillis = millis();
currentValue = tmpdata;
//split cmd in relay no and status
relayno = tmpdata / 10;
relay_status = tmpdata % 10;
loopFDRS();
if (currentMillis - previousMillis >= interval) {
// save the last time you did something
previousMillis = currentMillis;
//if (currentValue != previousValue) {
//write new value
mcp.digitalWrite(relayno, relay_status);
// read relaystatus
int port_status_A= mcp.readGPIO(0);
int port_status_B= mcp.readGPIO(1);
// ToDo: convert portstatus to '1010010111001011'
//send data
loadFDRS(relayno,STATUS_T);
loadFDRS(relay_status,STATUS_T);
// loadFDRS(port_status_A,STATUS_T);
// loadFDRS(port_status_B,STATUS_T);
// DBG(sendFDRS());
if(sendFDRS()){
DBG("Relaynumber ");
DBG(relayno);
DBG("Relay status ");
DBG(relay_status);
//}
previousValue = currentValue;
// sleepFDRS(10); //Sleep time in seconds
}
}
Is it possible to add TEXT datatype?
Best Regards Håkan
Beta Was this translation helpful? Give feedback.
All reactions