I’m still learning what are the best practices for good code but can someone tell me if this is a good approach or not. I currently have multiple variables returning a single value and I want combine them to a JSON format and just have one Particle.variable that would return all the data.
Sample code below is.
String Data;
char buf[256];
int a
int b
void setup()
{
Particle.variable("JSON", Data);
}
void loop()
{
JSONBufferWriter writer(buf, sizeof(buf));
writer.beginObject();
writer.name("a").value(A);
writer.name("b").value(B);
writer.endObject();
writer.buffer()[std::min(writer.bufferSize(), writer.dataSize())] = 0;
Data = buf;
}
int enableAlerts(String command)
{
if (command.equalsIgnoreCase("1"))
{
A = 1;
EEPROM.put(setAlertEEPROMLocation, A);
return 1;
}
else
{
A = 0;
EEPROM.put(setAlertEEPROMLocation, A);
return 0;
}
}
int enablePhonePowerAlerts(String command)
{
if (command.equalsIgnoreCase("1"))
{
B = 1;
EEPROM.put(setAlertPhonePowerEEPROMLocation, B);
return 1;
}
else
{
B = 0;
EEPROM.put(setAlertPhonePowerEEPROMLocation, B);
return 0;
}
}