Datastream Fahrenheit Units Issues

I’d suggest that you start by posting your FULL sketch.

Pete.

1 Like

Yep thats a fair callout. Here it is.

#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <max6675.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define BLYNK_TEMPLATE_ID "XXXX"
#define BLYNK_TEMPLATE_NAME "XXXX"
#define BLYNK_AUTH_TOKEN "XXXX"
 
#define SCREEN_WIDTH 128    // OLED display width, in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels
#define OLED_RESET -1       // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
char auth[] = "XXXX";    // You should get Auth Token in the Blynk App.
char ssid[] = "XXXX";                       // Your WiFi credentials.
char pass[] = "XXXX";
 
int ktcSO = 12;
int ktcCS = 13;
int ktcCLK = 14;
 
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
 
void setup() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  Serial.println("Max6675 test");
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c); //initialize with the I2C addr 0x3C (128x64)
  delay(500);
  display.clearDisplay();
  display.setCursor(25, 15);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println(" Thermometer");
  display.setCursor(25, 35);
  display.setTextSize(1);
  display.print("Initializing");
  display.display();
  delay(3000);
}
 
void loop()
{
  Blynk.run();
  float DC = ktc.readCelsius();
  // Read temperature as Celsius
  float DF = ktc.readFahrenheit();
 
  Serial.print("C = ");
  Serial.print(ktc.readCelsius());
  Serial.print("\t F = ");
  Serial.println(ktc.readFahrenheit());
 
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(20, 0);
  display.print("Temperature");
 
  display.setTextSize(2);
  display.setCursor(10, 20);
  display.print(ktc.readCelsius());
  display.print((char)247);
  display.print("C");
 
  display.setTextSize(2);
  display.setCursor(10, 45);
  display.print(ktc.readFahrenheit());
  display.print((char)247);
  display.print("F");
  display.display();
 
  Blynk.virtualWrite(V0, ktc.readCelsius());
  Blynk.virtualWrite(V1, ktc.readFahrenheit());
  delay(1000);
}

Thanks

Vovovovovo

Your loop is a complete mess.

Read this
Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

As @Madhukesh said, your void loop is a mess.

You are also taking readings and storing them in the variables DC and DF, but then you aren’t using these variables again. Instead, you’re repeatedly taking new readings. This is the wrong approach.
When you move all of this junk out of your void loop and into a function that’s called with a BlynkTimer (and of course delete the delay command) you should structure the function so that you take readings at the beginning of this function and store them in variables, then use these variables when you send the values to the serial monitor, LCD and Blynk.

Pete.

1 Like

Thats good feedback from both you. I’ll have a closer look and adjust. Thanks

Well… I’m no expert but I tried to follow your advice and based on the great post you did Using BlynkTimer or SimpleTimer and this is the current status…

#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <max6675.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
 
#define SCREEN_WIDTH 128    // OLED display width, in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels
#define OLED_RESET -1       // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
char auth[] = "";    // You should get Auth Token in the Blynk App.
char ssid[] = "";                       // Your WiFi credentials.
char pass[] = "";
 
int ktcSO = 12;
int ktcCS = 13;
int ktcCLK = 14;
 
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

// This function creates the timer object. It's part of Blynk library 
BlynkTimer timer; 

void getTemp()
{
  float DC = ktc.readCelsius();
  float DF = ktc.readFahrenheit();
  Blynk.virtualWrite(V0, DC);
  Blynk.virtualWrite(V1, DF);
  Serial.print("C = ");
  Serial.print(DC);
  Serial.print("\t F = ");
  Serial.println(DF);
 
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(20, 0);
  display.print("Temperature");
 
  display.setTextSize(2);
  display.setCursor(10, 20);
  display.print(DC);
  display.print((char)247);
  display.print("C");
 
  display.setTextSize(2);
  display.setCursor(10, 45);
  display.print(DF);
  display.print((char)247);
  display.print("F");
  display.display();
}
 
void setup() 
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, getTemp);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3c); //initialize with the I2C addr 0x3C (128x64)
  delay(500);
  display.clearDisplay();
  display.setCursor(25, 15);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println(" Thermometer");
  display.setCursor(25, 35);
  display.setTextSize(1);
  display.print("Initializing");
  display.display();
  delay(3000);
}
 
void loop()
{
  timer.run(); // call the BlynkTimer object
  Blynk.run(); // perform a handshake with the Blynk server
}

And unfortunately I’m still getting the same results. I’m attaching a side by side photo of the lcd and the blynk on the phone. This photo is with No Units defined on the Datastream V1. It shows the right value… I tried with setInterval 1sec and 5sec. Same result.

PS: The code does look cleaner, thanks for the tip.

What happens if you setup the data stream with units?

It seems to use the C value but looks funny on the bottom… Same has before… see screenshots.

will attach datastream definition to other reply…

What do you see if you add two gauges to the web dashboard (and I’m not interested in the template preview screen, it means nothing)?

Also, if your desired range is 0°C to 600°F then the min/max for your Fahrenheit datastream should be 32 to 1112

Pete.

I’ve corrected the datastream Min and Max and heres a screenshot of the web dashboard. Shows the exact same issue as the iOS App version.

And before you tell me the min and max are wrong. heres the screenshot of the datastream def with the new max/min

Heres a screenshot of the web without the Units defined. Shows the right value and the max/min correct.

Looks like a bug to me.

@Oleksii-QA any thoughts on this?

Pete.

I will check

2 Likes

Thanks. Please let me know if you need more data from my side.

@rechena hello, did you change settings in the organization settings?

screenshot-blynk-qa.com-2023.03.01-10_31_50

We have a feature for automatic convertion from celsius to fahr. However, it is not yet fully done, so this switch with “Units” within organization settings should be hidden from the end users. But it may be a bug that it is now visible. We’re checking. If it is visible for you - you need to set it to “Default”, which means - no conversion will happen.

Hi, humm, where do I find that option? I’m on the free plan, so the only thing I see is these settings on my account.

So I’m assuming I’m on the “hidden from users” :slight_smile:

Thanks

@rechena please check in iOS app

Only have this…

ps: sorry couldn’t post faster since I’m a new user so limited answers :joy: