Bando IoT

Bando IoT adalah bando yang terdapat lampu yang dapat menyala dengan kontrol jarak jauh via internet.

IntermediateProtip2 hours102
Bando IoT

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1
AA Batteries
AA Batteries
×2
SparkFun FTDI Basic Breakout - 3.3V
SparkFun FTDI Basic Breakout - 3.3V
×1
LED (generic)
LED (generic)
×2

Software apps and online services

Arduino IDE
Arduino IDE
API agnosthings

Story

Read more

Code

bando iot

Arduino
sketch bando IoT
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

ESP8266WiFiMulti WiFiMulti;

int lampuBando = 13; //pin pada lampu adalah pin 13

void setup()
{
    Serial.begin(9600);

    WiFiMulti.addAP("SSID", "PASSWORD"); //nama wifi dan password wifi

    pinMode(lampuBando, OUTPUT);
    digitalWrite(lampuBando, LOW);
}

void loop()
{
    if((WiFiMulti.run() == WL_CONNECTED))
    {
        HTTPClient http;

        http.begin("http://agnosthings.com/9e82492c-5081-11e6-8001-005056805279/field/last/feed/591/bandoNyala"); //copy paste URL API Last feed dari agnosthings.com

        int httpCode = http.GET();

        if(httpCode > 0)
        {
    
            Serial.printf("[HTTP] GET... code: %d\n", httpCode);

            if(httpCode == HTTP_CODE_OK)
            {
                String json = http.getString();
                Serial.println(json);

                if(json == "{\"value\":\"bandoNyala\",\"code\":200}"){
                    digitalWrite(lampuBando, HIGH); //Lampu LED pada bando akan menyala
                    delay(5000);
                }
                else{
                   digitalWrite(lampuBando, LOW);
                }
            }

        } else {
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
    }

    delay(2000);
}

Credits

dirakit community

dirakit community

122 projects • 73 followers
Indonesia IoT Community
Sulis Priyanto

Sulis Priyanto

13 projects • 1 follower
Monalisa Arcelia

Monalisa Arcelia

9 projects • 5 followers

Comments

Add projectSign up / Login