Hi
I've seen many people talking about "don't use Strings, as they always bring troubles", and well, it's true indeed, I'm experiencing crashes sometimes, as they consume much dynamic memory.
The problem is, Strings are a lot easier to manipulate, and I'm having some problems doing the data treatment with the char arrays.
The problem is the following, I'm reading many parameters from sensors (temperature, humidity, gas levels, from MQ-4 and MQ-7 sensors), and I want to do some data treatment (if I can name it that way) with the chars, for example:
- DHT11 return 28 (That means 28-degree Celcius), and I want to convert that 28 into !28;
You may be asking why I'm doing it, well it's because I'm having interference with jumpers and sometimes some trash comes with the message, so, when this !28; arrives at the ESP8266. it can clear all the data that comes with the 28 (it it does)
The code (with the Strings) that I have is the following:
Readings (all ok there, I think):
MQ4_Value = digitalRead(MQ4); // mq-4 gas sensor value
MQ7_Value = digitalRead(MQ7); // mq7 gas sensor value
float temp = dht.readTemperature(); // temperature value
float hmdt = dht.readHumidity(); // humidity value
Data treatment (there is the problem):
String MQ4_Value_forSend;
String MQ7_Value_forSend;
String temp_forSend;
String hmdt_forSend;
temp_forSend = String(F("!")) + String(temp) + String(F(";"));
hmdt_forSend = String(F("!")) + String(hmdt) + String(F(";"));
MQ4_Value_forSend = String(F("!")) + String(MQ4_Value) + String(F(";"));
MQ7_Value_forSend = String(F("!")) + String(MQ7_Value) + String(F(";"));
As you see, I'm making extreme use of String objects, as they are easier to manipulate. But, how can I do such treatment with char arrays?
Thanks in advance
Pedro