Created
February 26, 2024 14:58
-
-
Save Vatsalya-singhi/081e34201e00ab8cf71dad0bf8d5cc20 to your computer and use it in GitHub Desktop.
ui code base
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MQTT PUB CODE | |
const publish_led_status = (value) => { | |
// Publish the message to the specified topic | |
client.publish(topic, String(value), (err) => { | |
if (!err) { | |
console.log('Message published:', value); | |
} | |
setLedStatus(value); | |
}); | |
}; | |
// MQTT PUB CODE | |
// HEAT INDEX CODE | |
const calculateHeatIndex = (temperatureCelsius, humidity) => { | |
temperatureCelsius = Number(temperatureCelsius); | |
humidity = Number(humidity); | |
// Convert Celsius to Fahrenheit | |
var temperatureFahrenheit = (temperatureCelsius * 9 / 5) + 32; | |
// Ensure the temperature is in Fahrenheit | |
if (temperatureFahrenheit < 80 || humidity < 40) { | |
return Number(temperatureCelsius); // Use the actual temperature if conditions are not met | |
} | |
// Calculate the heat index in Fahrenheit | |
var heatIndexFahrenheit = -42.379 + | |
2.04901523 * temperatureFahrenheit + | |
10.14333127 * humidity - | |
0.22475541 * temperatureFahrenheit * humidity - | |
6.83783e-03 * temperatureFahrenheit * temperatureFahrenheit - | |
5.481717e-02 * humidity * humidity + | |
1.22874e-03 * temperatureFahrenheit * temperatureFahrenheit * humidity + | |
8.5282e-04 * temperatureFahrenheit * humidity * humidity - | |
1.99e-06 * temperatureFahrenheit * temperatureFahrenheit * humidity * humidity; | |
// Convert the Heat Index back to Celsius | |
var heatIndexCelsius = (heatIndexFahrenheit - 32) * 5 / 9; | |
return Math.floor(Number(heatIndexCelsius)); | |
} | |
// HEAT INDEX CODE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment