• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

DS18B20 sensor MQTT doubt

Q&A Forum › Category: Other › DS18B20 sensor MQTT doubt
0 Vote Up Vote Down
José Magalhães asked 4 years ago

Hello.
could you be so kind as to explain with more detail de line of code (Microython ESP32 and ESP8266 page261:
msg = (b'{0:3.1f}’.format(temp))
.why the outer parentesis?
{0:3.1f} is some kind of diccionary entry?
what does de .fomat(temp) method do?
so sorry if my questions make little sense but I’m just starting
thanks in advance
 

Question Tags: MicroPython
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.
 
{0:3.1f} is a way of formatting number (in this case, the temperature value).
f for float; 3 for the total number of places to be reserved for the whole string, 1 for the decimal places.
 
For a more detailed explanation, I recommend reading this article:

  • https://mkaz.blog/code/python-string-format-cookbook/

 
As for the b’, it converts the value into bytes literal. This article explains it well for beginners:

  • https://www.studytonight.com/post/significance-of-prefix-b-in-a-string-in-python

 
I hope this helps.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.