Notecarrier F uploading data decimal positions, power options?

I bought these boards:

  • Notecarrier F (Feather)
  • Notecard Cellular

I am using it with a adafruit esp32 s3 feather. As a first test I am using a simple arduino program to upload a simulated temperature reading every 5 minutes and route it to adafruit IO cloud service. Everythinig seems to be working but when I view events on the project it shows alot of decimal positions. I read another post and it suggested to do the rounding in the arduino code and the value looks ok in the arduino serial monitor 51.90 but it still shows up in events as 51.90000152587891

Also I have a question on how to power the board. I currently use a LIPO battery connected to the note carrier “vbat” jst and when I am writing code I have the esp32 board connected to my laptop with a USB cable. There is also a USB connector on the note carrier board, should I being using that to power it once I am done testing code or power the esp32 board ?

thanks

{“temp”:51.90000152587891} (from events viewer)

output from arduino serial monitor:
18:58:08.308 → setup starting
18:58:08.308 → Scanning…
18:58:08.308 → I2C device found at address 0x17
18:58:08.355 → I2C device found at address 0x36
18:58:08.355 → I2c scan done
18:58:08.355 →
18:58:11.377 → notecard.newRequest
18:58:12.364 → [INFO] {“req”:“hub.set”,“product”:“com.gmail.msy380:test1”,“mode”:“periodic”,“body”:{“agent”:“note-arduino 1.6.6”,“compiler”:“gcc 8.4.0”,“req_interface”:“i2c”,“cpu_name”:“esp32”},“crc”:“0000:B4FD6481”}
18:58:12.645 → [INFO] {}
18:58:12.645 → notecard ready
18:58:14.618 → setup done
19:03:14.629 → wakeup
19:03:15.648 → 51.90
19:03:15.648 → [INFO] {“req”:“note.add”,“body”:{“temp”:51.90000152587891},“crc”:“0001:2C27BFFC”}
19:03:15.883 → [INFO] {“total”:1}
19:03:15.883 → [INFO] {“req”:“hub.sync”,“crc”:“0002:10BAC79A”}
19:03:16.040 → [INFO] {}

here is the function I am calling to post new data:

void getSensorData() // this runs every 5 minutes
{

temperature = temperature + 1.1;  // simulate some data
humidity = humidity + 1.2;

// Workaround: To control the decimal places, you would need to format or truncate the number before using JAddNumberToObject.
// For example, you could round the number to the desired number of decimal places using standard C/C++ or
// Arduino functions before adding it to the JSON object. A suggested workaround in a Blues Community Forum
// post was to multiply the floating-point value by 100, store it as an integer, send it, and then divide by 100 when needed.

int roundedInt;
float roundedFloat;
roundedInt = (int)(temperature * 100);
roundedFloat = (float)roundedInt / 100;
Serial.println(roundedFloat); // displayed 51.90

J *req = notecard.newRequest("note.add");
if (req != NULL)
{
    
    J *body = JAddObjectToObject(req, "body");
    
    if (body)
    {
        JAddNumberToObject(body, "temp", roundedFloat);
        //JAddNumberToObject(body, "humidity", humidity);
    }
    notecard.sendRequest(req);
    notecard.requestAndResponse(notecard.newRequest("hub.sync"));  // force a sync
}
else
{
  neoPixel.setPixelColor(0,red);  
  neoPixel.show ();
  delay(3000);
  neoPixel.clear();
  neoPixel.show ();
}

}

Hi @JimK and welcome to the Blues community!

I think you’re seeing 51.90000152587891 because you’re sending a raw 32-bit float into JSON. Even though you print 51.90 to the serial console, the binary float is really 51.90000152587890625…so Notehub shows you the complete precision. Without testing this myself, I’m pretty sure you can do this:

float temp = readTempSensor(); 
temp = roundf(temp * 100.0f) / 100.0f; 

Regarding your power question, you should always power everything from the Notecarrier. So connecting a LiPo battery to the Notecarrier is all you need to do when you deploy.

Thanks,
Rob

Hi Rob, thanks for the quick reply, the code suggestion compiled OK but it still uploads with 14 decimal positions. I changed it to convert to a char array, dtostrf(temperature, 6, 1, str); used a JAddStringToObject(body, “temp”, str); and it uploaded ok and looks ok in the adafruit IO feed.

Just to clarify all I need to do is have a solar panel with a JST connector and plug that into the carrier board ‘solar’ , have a LIPO battery attached to ‘vbat’ and the carrier board has the circuitry to automatically charge the LIPO ?

Thanks

Hi @JimK,

Sorry about that! That’s what I get for sending out untested code :slight_smile:.

And yes per the datasheet that’s all you need to do re: solar (provided your panel is within the specs listed).

Thanks,
Rob

1 Like

Hi Rob
thanks for the link to the datasheet with details how to power the notecarrier board using a solar panel and LIPO batter

1 Like