I successfully connected to a RN4871U module with my Nano 33 IoT.
Now, after I read the sensor-data of a specific characteristic, I can print
the correct data in the console with:
for(int i = 0; i < 8; i++)
{
Serial.print(value[i]);
}
This is nice and works, but I want the complete array in one variable.
How is that possible?
I tried it with atoi, but it didnt seem to work. It returns 0 in the serial monitor.
The characteristic reading part of my code looks like this at the moment:
// Value Anzeige
int gunstatus; // Here the the values of "value[0], value[1] ... value[8] one after another should go
char value[8];
while (peripheral.connected()) {
if (GunCharacteristic.valueUpdated()) {
GunCharacteristic.readValue(value,8);
gunstatus = atoi(value);
for(int i = 0; i < 8; i++)
{
Serial.print(value[i]);
}
Serial.println("");
Serial.println(value[7]); // Value [7] is the only value i need, but i want to know how to get every 9 values into the "gunstatus" variable
Serial.println("");
Serial.print("Gunstatus: ");
Serial.println(gunstatus); // prints 0
Use writeln() instead of print() and show the result.
If you request only
If you are sure that exactly value[7] contains the expected value then assign it to gunstatus like gunstatus = value[7] - '0'; //convert ASCII to digital value