ALAT UKUR SUHU TUBUH DENGAN SENSOR MLX90614 BERBASIS NODEMCU DENGAN TAMPILAN APLIKASI TELEGRAM

PROGRAM UNTUK MEMBACA SUHU DAN DIKIRIM KE APLIKASI TELEGRAM DENGAN WIFI 

#include <Wire.h>

#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

char ssid[] = "SOMI BIRI";     // diisi nama wifi

char password[] = "XXXXXXX"; // diisi password wifi

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

#include <UniversalTelegramBot.h>

#define BOTtoken "1996424470:AAGLUsvPsLKWnsz-SUiVm5bT-_rzPYKjNe8" // diisi Token Bot (Dapat dari Telegram Botfather)

WiFiClientSecure client;

UniversalTelegramBot bot(BOTtoken, client);

int botRequestDelay = 1000;

unsigned long lastTimeBotRan;

void handleNewMessages(int numNewMessages) {

  Serial.println("handleNewMessages");

  Serial.println(String(numNewMessages));

  for (int i=0; i<numNewMessages; i++) {

    String chat_id = String(bot.messages[i].chat_id);

    String text = bot.messages[i].text;

    String from_name = bot.messages[i].from_name;

    if (from_name == "") from_name = "Guest";

    if (text == "/start") {

      String welcome = "Welcome  " + from_name + ".\n";

      welcome += "/statussuhu : Status Suhu\n";

      welcome += "/statuskelembapan : Status Kelembapan\n";

      bot.sendMessage(chat_id, welcome, "Markdown");

    }

    if (text == "/suhu") {

       String temp = "Suhu Tubuh =  ";

       temp += mlx.readObjectTempC();

       temp += " *C";

       bot.sendMessage(chat_id,temp, "");

    }

  }

}

void setup() {

  Serial.begin(9600);

  mlx.begin();

  client.setInsecure();

  WiFi.mode(WIFI_STA);

  WiFi.disconnect();

  delay(100);

  Serial.print("Connecting Wifi: ");

  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {

    Serial.print(".");

    delay(500);

  }

  Serial.println("");

  Serial.println("WiFi connected");

  Serial.print("IP address: ");

  Serial.println(WiFi.localIP());}

void loop() {

  if (millis() > lastTimeBotRan + botRequestDelay)  {

    int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    while(numNewMessages) {

      Serial.println("got response");

      handleNewMessages(numNewMessages);

      numNewMessages = bot.getUpdates(bot.last_message_received + 1);

    }

    lastTimeBotRan = millis();

  }

}

Komentar