SlideShare a Scribd company logo
Serial Data from Arduino to Raspberry Pi
to MySQL using CoAP Protocol
By Deligence Technologies
www.deligence.com
Getting Serial Data from Arduino to Raspberry Pi and saving
it in MySQL database & Explaining how to run CoAP server
on Raspberry Pi -
In this tutorial I'm going to tell you how we can get the sensor
data from Arduino Uno and sending it to the Raspberry pi
through UART. Mostly We are going to do two important things.
First we will use a CoAP server For making a GET request which
will run on raspberry pi and in our CoAP browser we will get the
DHT22 data immediately. And the second thing is we are going
to make a mysql database in raspberry pi to store the value of
DHT22 sensor.
Constrained Application Protocol (CoAP) is an Internet Application Protocol for constrained
devices. It enables those constrained devices to communicate with the wider Internet using
similar protocols. CoAP is designed for use between Devices on the same constrained
network, between Devices and general nodes on the Internet, and between Devices on
different constrained networks both joined by an Internet.
CoAP is designed to easily translate to HTTP for simplified integration with the web, while
also meeting specialized requirements such as multicast support, very low overhead, and
simplicity.
CoAP supports the basic methods of GET, POST, PUT, DELETE, which are easily mapped to
HTTP.
Now here above was the brief description of CoAP. As I told you that you will get a lot of
things about CoAP but as far as interfacing with real hardware is concerned there are very
less stuff. So that's why I am going to tell you about this CoAP server and how we can interact
with real hardware.
1. In this step we will tell you that how we can run a CoAP server in our raspberry pi.
txThings Tutorial :
In this tutorial, we will describe how to run a CoAP server on Raspberry Pi, and run the CoAP
client on a PC. The CoAP server and clients are implemented using txThings, which is a
Phyton implementation of CoAP.
ABOUT TXTHINGS
txThings - CoAP library for Twisted framework
txThings is a Python implementation of Constrained Application Protocol (CoAP):
http://tools.ietf.org/html/rfc7252
txThings is based on Twisted - asynchronous I/O framework and networking engine written
in Python.
http://twistedmatrix.com/
txThings uses MIT License (like Twisted itself).
http://opensource.org/licenses/mit-license.php
Copyright (c) 2012 Maciej Wasilak
http://sixpinetrees.blogspot.com/
txThings has the following features:
 Support for draft-ietf-core-coap-13 - including automatic piggyback/separate response
handling. No caching support.
 Support for draft-ietf-core-block-12 (no support for server initiative though - waiting for
the resolution)
 Limited support for RFC6690 (Core Link Format) - server only.
Other nice things:
 txThings works nicely on RaspberryPi
 txThings is compatible with Kivy - brilliant new Python GUI library (I'll post some examples
soon).
 txThings is fully asynchronous (thanks to twisted framework)
txThings is posted on Github. The easiest way to get it is to clone the repository to your local
machine using the command below:
git clone git://github.com/siskin/txThings.git
Library contains CoAP code (inside "iot" directory) and three examples:
server.py - CoAP server that starts on localhost, port 5683 and hosts several resources
client_GET.py - example client which performs GET request to localhost, port 5683
client_PUT.py - example client which performs PUT request to localhost, port 5683
Client_GET and client_PUT both use port 61616 - to use them simultaneously change port
number in one of the clients. Server will send blockwise responses for default settings. To use
txThings you need Python 2.7 with Twisted installed (I suggest using the latest Twisted
version, but older releases also work - tested with 11.1).
1. Install OS on Raspberry Pi (set the appropriate raspi-config for all,including ssh and
desktop boot)
2. Install setup tools for python (such as pip)
https://pip.pypa.io/en/stable/installing.html#install-pip
3. Install Twisted on Raspberry Pi
sudo apt-get install python-pip
pip install twisted==15.1.0
4. Install txThings on Raspberry Pi
pip install txThings
2. Now this is the time to move on Arduino. Here I've connected DHT22 sensor to
an arduino and our arduino is connected to our raspberry pi(which is working here
as an IOT gateway or server ) through USB cable to one of its USB port. But before
going to connect Arduino to our raspberry pi we have to put a Arduino snippet for
DHT22 interfacing to our arduino. Since we are using Raspberry pi remotely in
ubuntu.
Connect your arduino to your PC to upload this code (Arduino code). Now just
unplug your arduino from PC and connect it to your pi.
3. Now we need to install some of the things to get data in raspberry pi
First one is Python-serial and then python-mysqldb.
Now this URI we have to type in Mozilla Firefox -
caop://<Raspberry pi IP Address>:5683
For that we need to do a little modification in our server.py code which we got while
installing txThings.
You just check your server.py code and edit accordingly. Now we need to run our server.py
code. It'll take a little time.
Here, you can see the temperature and humidity in Copper on firefox.
Humidity Temperature and Heat Index
The Copper (Cu) CoAP user-agent is an add-on for the Firefox Web browser. It allows
browsing, bookmarking, and direct interaction with CoAP resources. Simply enter a CoAP URI
into the address bar.
For getting the data in our smartphone we need to install Aneska. At the end section of the
video you can see how we can get data in our smartphone.
Humidity and Temperature In Smartphone
The Second Part of this Project is creating a Database of DHT22 Data
For that you have to install Apache Mysql and PHP and then save data in phpmyadmin.
You can easily get about these installation in many links. So I'm not going to demonstrate
that. In short you have to set up a LAMP server in your raspberry pi. I am assuming you have
install these necessary things.
So Let's get started -
• Go to localhost/phpmyadmin or <pi IP address>/phpmyadmin (if you are using pi remotely)
• Create Database give it some name
• Then create table for that
• I have made 6 columns
• For getting the data in database from arduino serial out we have to write a small script in
pi.
This is the script(You can find all the files in our github page -
https://github.com/DeligenceTechnologies/Serial-Data-from-Arduino-to-Raspberry-Pi-to-
MySQL-using-CoAP-Protocol) for getting data in mysql datbase from arduino.
If I run this script I can see the updated data in database but if we want this thing
automatically let's say for every single minute then we have to edit crontab -e
All the process Regarding this project is explained in our video that you can see in the slide
15.
Arduino Interfacing with DHT22 and connected to Pi with USB
Arduino Connection with DHT22
We at Deligence Technologies, offer a range of Arduino Software Development Services
to turn your design into a fully functional system.
Deligence Technologies - your growing technology partner!
www.deligence.com/contact-us
Email : info@deligence.com
Phone : +91 9910130340
Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol

More Related Content

PDF
Esp8266 basics
PPTX
Attendance system using MYSQL with Raspberry pi and RFID-RC522
PPTX
Attendance System using ESP8266(Wi-Fi) with MySQL
PPT
XBee and RFID
PPTX
Open Source Home Automation with LinkSprite.IO
PPTX
Arduino & NodeMcu
PDF
Programando o ESP8266 com Python
PDF
Rdl esp32 development board trainer kit
Esp8266 basics
Attendance system using MYSQL with Raspberry pi and RFID-RC522
Attendance System using ESP8266(Wi-Fi) with MySQL
XBee and RFID
Open Source Home Automation with LinkSprite.IO
Arduino & NodeMcu
Programando o ESP8266 com Python
Rdl esp32 development board trainer kit

What's hot (18)

PPTX
IoT with openHAB on pcDuino3B
PPTX
Esp8266 NodeMCU
PDF
Republic of IoT - Hackathon Hardware Kits Hands-on Labs
PDF
lesson1 - Getting Started with ESP8266
PPTX
Esp8266 - Intro for dummies
PDF
Introduction to RIoT Hardware Kits & ESP32 Programming [Road to RIoT 2017]
PDF
NodeMCU with Blynk and Firebase
PDF
⭐⭐⭐⭐⭐ CHARLA MACI: Prototipado de Aplicaciones Industriales Basado en Hardwar...
PDF
Road to Republic of IoT - ESP32 Programming and LoRa
PDF
Esp32 cam arduino-123
PPT
Arduino Meetup with Sonar and 433Mhz Radios
PPTX
ESP8266 Wifi Nodemcu
PDF
RFID Reader 125KHz USB Serial
PDF
Introduction to ESP32 Programming [Road to RIoT 2017]
PDF
lesson2 - Nodemcu course - NodeMCU dev Board
PDF
[codemotion] Arduino Yun: internet for makers
PDF
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
PDF
Lesson 9- NodeMCU with Arduino UNO (UART)
IoT with openHAB on pcDuino3B
Esp8266 NodeMCU
Republic of IoT - Hackathon Hardware Kits Hands-on Labs
lesson1 - Getting Started with ESP8266
Esp8266 - Intro for dummies
Introduction to RIoT Hardware Kits & ESP32 Programming [Road to RIoT 2017]
NodeMCU with Blynk and Firebase
⭐⭐⭐⭐⭐ CHARLA MACI: Prototipado de Aplicaciones Industriales Basado en Hardwar...
Road to Republic of IoT - ESP32 Programming and LoRa
Esp32 cam arduino-123
Arduino Meetup with Sonar and 433Mhz Radios
ESP8266 Wifi Nodemcu
RFID Reader 125KHz USB Serial
Introduction to ESP32 Programming [Road to RIoT 2017]
lesson2 - Nodemcu course - NodeMCU dev Board
[codemotion] Arduino Yun: internet for makers
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
Lesson 9- NodeMCU with Arduino UNO (UART)
Ad

Similar to Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol (20)

PDF
Projects list raspberry pi projects complete 1480 projects
PDF
SDARPiBot - VLES'16
PPTX
IOT notes ....,.........
PPTX
IoT for data science Module 5 - Raspberry Pi.pptx
PDF
Projects list 1271 raspberry pi projects
PDF
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
PDF
Projects list raspberry pi projects-1230 - projects
PDF
Embedded Web server using TCP/IP protocol
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PPT
Server/Client Remote platform logger.
DOCX
Report for weather pi
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PDF
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
PDF
IoT Implementation of Sensor Data Acquisition in Surveillance Applications - ...
PDF
IoT Implementation of Sensor Data Acquisition in Surveillance Applications - ...
PPTX
5-Tut3_Networking_with_Python.pptx good intro
PPTX
Up and running with Raspberry Pi
PDF
Advanced View of Projects Raspberry Pi List.pdf
Projects list raspberry pi projects complete 1480 projects
SDARPiBot - VLES'16
IOT notes ....,.........
IoT for data science Module 5 - Raspberry Pi.pptx
Projects list 1271 raspberry pi projects
Raspberry Pi By Example 1st Edition Pajankar Ashwin Kakkar Arush
Projects list raspberry pi projects-1230 - projects
Embedded Web server using TCP/IP protocol
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
Server/Client Remote platform logger.
Report for weather pi
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
Advanced View of Projects Raspberry Pi List - Raspberry PI Projects.pdf
IoT Implementation of Sensor Data Acquisition in Surveillance Applications - ...
IoT Implementation of Sensor Data Acquisition in Surveillance Applications - ...
5-Tut3_Networking_with_Python.pptx good intro
Up and running with Raspberry Pi
Advanced View of Projects Raspberry Pi List.pdf
Ad

More from Sanjay Kumar (17)

PPT
Mobile app development
PPT
Accelerated Mobile Pages (AMP)
PPTX
Arduino to Control Bulbs using Web App
PPTX
Bulb Control using Web App with Raspberry Pi
PPTX
Obstacle detection Robot using Ultrasonic Sensor and Arduino UNO
PPTX
Arduino Interface LM35 MQTT Using UART
PPTX
Arduino Interface with MySQL for Storing RFID Access Details
PPTX
Rain Drop Sensor using Arduino!
PPTX
Arduino Programming Software Development
PPTX
Embedded Software Development
PPTX
Ionic - Hybrid Mobile Application Framework
PPTX
Internet of Things - IOT
PPTX
Meteor Mobile App Development
PPTX
Digital Marketing Strategy
PPTX
Web Application Development
PPTX
Joomla Website Development Company
PPTX
Meteor js App Development
Mobile app development
Accelerated Mobile Pages (AMP)
Arduino to Control Bulbs using Web App
Bulb Control using Web App with Raspberry Pi
Obstacle detection Robot using Ultrasonic Sensor and Arduino UNO
Arduino Interface LM35 MQTT Using UART
Arduino Interface with MySQL for Storing RFID Access Details
Rain Drop Sensor using Arduino!
Arduino Programming Software Development
Embedded Software Development
Ionic - Hybrid Mobile Application Framework
Internet of Things - IOT
Meteor Mobile App Development
Digital Marketing Strategy
Web Application Development
Joomla Website Development Company
Meteor js App Development

Recently uploaded (20)

PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
PPTX
Belt and Road Supply Chain Finance Blockchain Solution
PDF
Smarter Business Operations Powered by IoT Remote Monitoring
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
PPTX
How to Build Crypto Derivative Exchanges from Scratch.pptx
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
PDF
Top Generative AI Tools for Patent Drafting in 2025.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PDF
REPORT: Heating appliances market in Poland 2024
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
PPTX
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
GamePlan Trading System Review: Professional Trader's Honest Take
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
creating-agentic-ai-solutions-leveraging-aws.pdf
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Belt and Road Supply Chain Finance Blockchain Solution
Smarter Business Operations Powered by IoT Remote Monitoring
A Day in the Life of Location Data - Turning Where into How.pdf
How to Build Crypto Derivative Exchanges from Scratch.pptx
Event Presentation Google Cloud Next Extended 2025
Enable Enterprise-Ready Security on IBM i Systems.pdf
Top Generative AI Tools for Patent Drafting in 2025.pdf
Modernizing your data center with Dell and AMD
Chapter 2 Digital Image Fundamentals.pdf
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
Dell Pro 14 Plus: Be better prepared for what’s coming
REPORT: Heating appliances market in Poland 2024
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx

Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol

  • 1. Serial Data from Arduino to Raspberry Pi to MySQL using CoAP Protocol By Deligence Technologies www.deligence.com
  • 2. Getting Serial Data from Arduino to Raspberry Pi and saving it in MySQL database & Explaining how to run CoAP server on Raspberry Pi - In this tutorial I'm going to tell you how we can get the sensor data from Arduino Uno and sending it to the Raspberry pi through UART. Mostly We are going to do two important things. First we will use a CoAP server For making a GET request which will run on raspberry pi and in our CoAP browser we will get the DHT22 data immediately. And the second thing is we are going to make a mysql database in raspberry pi to store the value of DHT22 sensor.
  • 3. Constrained Application Protocol (CoAP) is an Internet Application Protocol for constrained devices. It enables those constrained devices to communicate with the wider Internet using similar protocols. CoAP is designed for use between Devices on the same constrained network, between Devices and general nodes on the Internet, and between Devices on different constrained networks both joined by an Internet. CoAP is designed to easily translate to HTTP for simplified integration with the web, while also meeting specialized requirements such as multicast support, very low overhead, and simplicity. CoAP supports the basic methods of GET, POST, PUT, DELETE, which are easily mapped to HTTP. Now here above was the brief description of CoAP. As I told you that you will get a lot of things about CoAP but as far as interfacing with real hardware is concerned there are very less stuff. So that's why I am going to tell you about this CoAP server and how we can interact with real hardware.
  • 4. 1. In this step we will tell you that how we can run a CoAP server in our raspberry pi. txThings Tutorial : In this tutorial, we will describe how to run a CoAP server on Raspberry Pi, and run the CoAP client on a PC. The CoAP server and clients are implemented using txThings, which is a Phyton implementation of CoAP. ABOUT TXTHINGS txThings - CoAP library for Twisted framework txThings is a Python implementation of Constrained Application Protocol (CoAP): http://tools.ietf.org/html/rfc7252 txThings is based on Twisted - asynchronous I/O framework and networking engine written in Python. http://twistedmatrix.com/ txThings uses MIT License (like Twisted itself). http://opensource.org/licenses/mit-license.php Copyright (c) 2012 Maciej Wasilak http://sixpinetrees.blogspot.com/
  • 5. txThings has the following features:  Support for draft-ietf-core-coap-13 - including automatic piggyback/separate response handling. No caching support.  Support for draft-ietf-core-block-12 (no support for server initiative though - waiting for the resolution)  Limited support for RFC6690 (Core Link Format) - server only. Other nice things:  txThings works nicely on RaspberryPi  txThings is compatible with Kivy - brilliant new Python GUI library (I'll post some examples soon).  txThings is fully asynchronous (thanks to twisted framework)
  • 6. txThings is posted on Github. The easiest way to get it is to clone the repository to your local machine using the command below: git clone git://github.com/siskin/txThings.git Library contains CoAP code (inside "iot" directory) and three examples: server.py - CoAP server that starts on localhost, port 5683 and hosts several resources client_GET.py - example client which performs GET request to localhost, port 5683 client_PUT.py - example client which performs PUT request to localhost, port 5683 Client_GET and client_PUT both use port 61616 - to use them simultaneously change port number in one of the clients. Server will send blockwise responses for default settings. To use txThings you need Python 2.7 with Twisted installed (I suggest using the latest Twisted version, but older releases also work - tested with 11.1).
  • 7. 1. Install OS on Raspberry Pi (set the appropriate raspi-config for all,including ssh and desktop boot) 2. Install setup tools for python (such as pip) https://pip.pypa.io/en/stable/installing.html#install-pip 3. Install Twisted on Raspberry Pi sudo apt-get install python-pip pip install twisted==15.1.0 4. Install txThings on Raspberry Pi pip install txThings
  • 8. 2. Now this is the time to move on Arduino. Here I've connected DHT22 sensor to an arduino and our arduino is connected to our raspberry pi(which is working here as an IOT gateway or server ) through USB cable to one of its USB port. But before going to connect Arduino to our raspberry pi we have to put a Arduino snippet for DHT22 interfacing to our arduino. Since we are using Raspberry pi remotely in ubuntu. Connect your arduino to your PC to upload this code (Arduino code). Now just unplug your arduino from PC and connect it to your pi. 3. Now we need to install some of the things to get data in raspberry pi First one is Python-serial and then python-mysqldb.
  • 9. Now this URI we have to type in Mozilla Firefox - caop://<Raspberry pi IP Address>:5683 For that we need to do a little modification in our server.py code which we got while installing txThings. You just check your server.py code and edit accordingly. Now we need to run our server.py code. It'll take a little time. Here, you can see the temperature and humidity in Copper on firefox. Humidity Temperature and Heat Index
  • 10. The Copper (Cu) CoAP user-agent is an add-on for the Firefox Web browser. It allows browsing, bookmarking, and direct interaction with CoAP resources. Simply enter a CoAP URI into the address bar.
  • 11. For getting the data in our smartphone we need to install Aneska. At the end section of the video you can see how we can get data in our smartphone. Humidity and Temperature In Smartphone
  • 12. The Second Part of this Project is creating a Database of DHT22 Data For that you have to install Apache Mysql and PHP and then save data in phpmyadmin. You can easily get about these installation in many links. So I'm not going to demonstrate that. In short you have to set up a LAMP server in your raspberry pi. I am assuming you have install these necessary things. So Let's get started - • Go to localhost/phpmyadmin or <pi IP address>/phpmyadmin (if you are using pi remotely) • Create Database give it some name • Then create table for that • I have made 6 columns • For getting the data in database from arduino serial out we have to write a small script in pi. This is the script(You can find all the files in our github page - https://github.com/DeligenceTechnologies/Serial-Data-from-Arduino-to-Raspberry-Pi-to- MySQL-using-CoAP-Protocol) for getting data in mysql datbase from arduino. If I run this script I can see the updated data in database but if we want this thing automatically let's say for every single minute then we have to edit crontab -e All the process Regarding this project is explained in our video that you can see in the slide 15.
  • 13. Arduino Interfacing with DHT22 and connected to Pi with USB
  • 15. We at Deligence Technologies, offer a range of Arduino Software Development Services to turn your design into a fully functional system. Deligence Technologies - your growing technology partner! www.deligence.com/contact-us Email : [email protected] Phone : +91 9910130340