Sunteți pe pagina 1din 15

IoT Sending Data on Server

INSTITUT TEKNOLOGI SEPULUH NOVEMBER


SURABAYA
Our Goals

The Purpose of this practice is to make IOT tools (Internet of things) which will be able to
monitor the temperature in real-time with transmission data through internet. Before we start the
practice, make sure you have installed the XAMPP Application, Arduion IDE. The tools that will
be needed in this practice are 1 temperature sensor (Ds18b20), 1 resistor, and 1 NodeMCU.

Step one

Crate circuit like shown in image down below or adjust as told by instructor.

Step two: Configure Arduino IDE

• First Download and Install Arduino IDE .


• Go to >> Files >> Preferences and paste following Link in "Additional board manager URL's"

http://arduino.esp8266.com/stable/package_esp8266com_index.json
• Click ok, Now Goto >> Tools >> Board >> Board Manager.
• Scroll down to find ESP8266 and click on install.

This will add all the ESP boards to the IDE.

• now you have to select the correct board , Here I have used NodeMCU 1.0 (ESP-12E
Module).
After selecting the board then follow settings below :

o Flash Size : "4M (3M SPIFFS)"


o Debug Port : "Disabled"
o Debug Level: "None"
o IWIP Variant: "V2 Lower Memory"
o CPU Frequency: "80Mhz"
o Upload Speed: "921600"
o Erase Flash: "Sketch On"
o Port : "COM port available" (where the device is connected should show up)
Step Three (Make Database)
• Open your XAMPP and Start it’s Apache and MySQL

• Open this url (localhost/phpmyadmin) in your browser then klick new

• Insert database name with name io and set Collation then klick Create
• Create table and give name data and set 4 colums then klick Go

• Fill columns identity like this image

Then scroll down and click Save


Step Four (Make connection between your server with your database)
• Open Notepad++ then copy this code and save in directory C:\xampp\htdocs\IO with
name connect with extension php
<?php

$host ="localhost"; //database hostname

$user ="root"; //database User ID

$pass =""; //database password

$database ="io";//database name

$connect=mysqli_connect($host,$user,$pass,$database) or die ("Connection Failed");

?>

• Open this localhost/IO/connect.php in your browser. If the web shown blank-page, then
you have successfully connect the data-base.
Step Five (Make php file for NodeMCU)
• Open Notepad++ then copy this code and save in directory C:\xampp\htdocs\IO with
name input with extension php
<?php

include 'connect.php';

$temperature=$_GET['temp'];

date_default_timezone_set("Asia/Jakarta");

$mydate=date("Y-n-j"); //years-month-day

$mytime=date("H:i:s"); //hours:minutes:second

$query="Insert into data (temperature,date, time) values ('$temperature','$mydate','$mytime')";

$proses=mysqli_query($connect,$query);

if($proses)

echo "Success";

else

echo "Failed Uploaded";

?>

• Open this localhost/IO/input.php?temp=27 in your browser. If the web shown “Success”


in the page, then your file has been successfully uploaded
Step Six (Make Arduino Program)
• Open your Arduino IDE and copy this code

#include <Arduino.h>

#include <ESP8266WiFi.h>

#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

#include <SoftwareSerial.h>

#include <OneWire.h>

#include <DallasTemperature.h>

#define ONE_WIRE_BUS D5

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

int getSensor(){

int Celcius=0;

sensors.requestTemperatures();

Celcius=sensors.getTempCByIndex(0);

Serial.print(" C ");

Serial.print(Celcius);

return Celcius;

}
void sendToServer(int mytemp){

if((WiFiMulti.run() == WL_CONNECTED)) {

String temper=(String)mytemp;

HTTPClient http;

http.begin("http://192.168.43.94/IO/input.php?temp="+temper); //change 192.168.43.94 with your


IP

USE_SERIAL.print("[HTTP] GET...\n");

// start connection and send HTTP header

int httpCode = http.GET();

delay(1000);

if(httpCode > 0) {

// HTTP header has been send and Server response header has been handled

USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

if(httpCode == HTTP_CODE_OK) {

String payload = http.getString();

USE_SERIAL.println(payload);

USE_SERIAL.write("Sent");

delay(3000);

USE_SERIAL.write("AT+CIPCLOSE\r\n");

}
void setup() {

delay(500); // Let the module self-initialize

USE_SERIAL.write("AT+CWQAP");

USE_SERIAL.begin(115200);

for(uint8_t t = 4; t > 0; t--) {

USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);

USE_SERIAL.flush();

delay(1000);

WiFiMulti.addAP("admin", "admin123");// Set Your (ID, Password) WiFi here

void loop() {

sendToServer(getSensor());

• Make sure you have changed the IP Server and Id, and your Wifi Password.
• Pair the NodeMCU with cable into your PC
• Choose tool>>port>>Your NodeMCU Port

• Save your project


Step Seven (Upload code in Node MCU)
• Klick Upload button and wait until 100%, then klick Serial Monior button

Upload Button
Serial Monitor Button

Wait Until 100%

• Make sure your Wifi is still on and the result from serial monitor will be shown like in
image down below.
• Check your database, and you have finished the practice.

S-ar putea să vă placă și