IoT Sending Data To Server
IoT Sending Data To Server
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.
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.
• 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 :
• 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
?>
• 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
$proses=mysqli_query($connect,$query);
if($proses)
echo "Success";
else
?>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
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;
USE_SERIAL.print("[HTTP] GET...\n");
delay(1000);
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
if(httpCode == HTTP_CODE_OK) {
USE_SERIAL.println(payload);
USE_SERIAL.write("Sent");
delay(3000);
USE_SERIAL.write("AT+CIPCLOSE\r\n");
}
void setup() {
USE_SERIAL.write("AT+CWQAP");
USE_SERIAL.begin(115200);
USE_SERIAL.flush();
delay(1000);
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
Upload Button
Serial Monitor Button
• 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.