Dht11 Failed to Get Reading Raspberry Pi
Store Data using NodeJS
Introduction
Raspberry Pi is a mini computer that has a digital input port output like on a microcontroller board. The advantages of Rasberry Pi compared to other microcontroller boards include having a port / connection for display in the grade of a Television or PC monitor and a USB connection for the keyboard and mouse. Raspberry Pi is made in English by the Raspberry Pi Foundation. At first Raspberry Pi was shown for the computer science learning module at school. To be able to save data on ANTARES, you can use the NodeJS Request. Here are the steps:
Figure 1. Raspberry Pi Device
ane. Install Raspberry Pi Bone
First, you must to have a Raspberry Pi that already has an OS. If you lot don't accept an Raspberry Pi that has an Os, yous can follow the tutorial on the page https://www.raspberrypi.org / documentation / installation / installing-images / . If you lot already have Raspberry Pi consummate with the Os, then you can continue to the next step.
two. Install Library
Activate Raspberry Pi and open the terminal window. After the terminal window opens, input the syntax below to initialize library npm every bit shown in Figure 2.
npm init --yep
Effigy ii. Initial NPM Library on Terminal UI
After inputting the syntax above, press enter and if the initialization procedure is successful so the terminal window brandish will wait like Figure three.
Figure 3. Initial NPM Library on Final UI
If y'all have successfully Islamized the NPM library and then install the NPM library by using the syntax beneath as shown in Figure iv.
npm install asking --salvage
Effigy iv. Install NPM Library on Concluding UI
Subsequently inputting the syntax to a higher place, press enter and if the installation process is successful the display of the terminal window will look like picture v.
Figure 5. Install NPM Library on Terminal UI
If the brandish is in accord with Figure five, the library installation procedure is complete.
3. Create NodeJS Request
Afterwards successfully installing the npm library, the side by side is to create a file with the NodeJS format. To create a file on Raspberry Pi, you tin employ the syntax below. This file is used to store data on the ANTARES platform.
sudo nano your-file-name.js
Figure half-dozen. Create File Syntax on Terminal UI
If it is entered into the JS Request Node file that will exist created. Enter the list below and don't forget to input your Device URL and your Access Central.
Store Information to ANTARES NodeJS Request Format
| Field | Value | |
|---|---|---|
| URL | https://platform.antares.id:8443/~/antares-cse/antares-id/your-application-name/your-device-name or https://platform.antares.id:8443/~/antares-cse/your-device-ID Note: | |
| Method | POST | |
| Header | Key | Value |
| X-M2M-Origin | access-id:access-countersign | |
| Content-Type | application/json;ty=4 | |
| Take | awarding/json | |
var asking = require("request"); var options = { method: 'POST', url: 'URL', headers: { 'cache-control': 'no-cache', 'content-type': 'application/json;ty=4', 'x-m2m-origin': 'access-id:access-password' }, body: '\r\due north{\r\n "m2m:cin": {\r\n "cnf": "message",\r\n "con": "\r\due north {\r\n \t \\"status\\": \\"0\\",\r\n \\"dim\\": \\"10\\"\r\due north }\r\n "\r\n }\r\due north}' }; request(options, function (error, response, body) { if (error) throw new Error(mistake); console.log(body); }); If it has been inputted, the display will be the aforementioned as in figure 7.
Figure 7. NodeJS File
To save your NodeJS Request file, yous demand to printing Ctrl + 10> Enter> Y.
4. Execute NodeJS Request
Afterwards the NodeJS Request file is saved. And then you tin can execute the file using the following sytanx.
sudo node your-file-name.js
Figure viii. Executed File & Result
If you get a response similar to Figure 8, Congratulations yous have successfully saved data on your device on ANTARES.
| Field | Value | |
|---|---|---|
| URL | https://platform.antares.id:8443/~/antares-cse/antares-id/your-application-name/your-device-name or https://platform.antares.id:8443/~/antares-cse/your-device-ID Note: | |
| Method | POST | |
| Header | Key | Value |
| X-M2M-Origin | admission-id:access-password | |
| Content-Type | application/xml;ty=iv | |
| Accept | application/xml | |
var request = require("request"); var options = { method: 'POST', url: 'URL', headers: { 'Cache-Control': 'no-enshroud', 'Content-Type': 'application/xml;ty=4', '10-M2M-Origin': 'access-id:access-password' }, trunk: '<m2m:cin xmlns:m2m=\"http://www.onem2m.org/xml/protocols\">\r\n <cnf>bulletin</cnf>\r\n <con>\r\n <obj>\r\northward <int name="data" val="16"/>\r\n <int name="unit of measurement" val="watt"/>\r\north <obj>\r\n \r\north' }; request(options, function (error, response, body) { if (mistake) throw new Error(error); panel.log(body); If it has been inputted, the display will exist the same as in effigy 7.
Figure 7. NodeJS File
To save your NodeJS Request file, you need to press Ctrl + X> Enter> Y.
4. Execute NodeJS Request
Subsequently the NodeJS Request file is saved. Then you tin can execute the file using the following sytanx.
sudo node your-file-proper name.js
Figure 8. Executed File & Result
If you get a response similar to Figure 8, Congratulations y'all take successfully saved data on your device on ANTARES.
5. Bank check Data on Device on ANTARES
Y'all tin check the data that you saved on the Device on ANTARES by opening the URL of your device.
Figure ix. ANTARES Device Brandish
Temperature and Humidity Monitoring using DHT11 Sensor
Introduction
In this tutorial, you volition create a temperature and humidity monitoring sistem using RaspberryPi, DHT11 sensor and ANTARES. DHT11 sensor volition measure out the temperature and humidity arround teh room, and then send the data so can exist monitored through device on ANTARES.
ane. Materials
The materials are:
a. Raspberry Pi
b. DHT11 Sensor
c. Resistor 10k ohm
d. Breadboard
eastward. Wire
Effigy 10. Materials
2. Wiring Diagram
Then yous need to connect the DHT11 sensor with Raspberry Pi. Connect DHT11 sensor with Raspberry Pi as shown in effigy 11 below. Use breadboard and jumper cables in the process of assembling.
Figure eleven. Wiring Diagram
Connect the DHT11 VCC sensor to the RaspberryPi three.3V pin, the DHT11 GND sensor to the RaspberryPi GND pin, the DHT11 sensor data to the RaspberryPi 4 GPIO and the pull upward resistor as shown.
3. Library DHT11 Installation
Before starting the process on the software, y'all demand to install the DHT11 Library on the RaspberryPi you lot are using. In this tutorial, y'all will utilise the DHT11 Library from Szazo. Open the Final window and type the post-obit code to start the installation.
git clone https://github.com/szazo/DHT11_Python.git After the installation process is complete, the DHT11_Python binder volition appear.
4. Programme Code
Afterward the library installation process is complete, you will create a plan code to read the sensor and send sensor data to the Antares Device. Before starting, make sure you have created the Application and Device on your Antares console.
Adjacent, enter to the DHT11_Python folder directory then open the dht11_example.py file using Python. And then the Python text editor window volition open, then type the program lawmaking as follows.
import RPi.GPIO as GPIO import dht11 import time import datetime import asking import json #initialize GPIO GPIO.setwarnings(Imitation) GPIO.setmode(GPIO.BCM) GPIO.cleanup() #read data using pin 4 example = dht11.DHT11(pin=iv) while True: result = instance.read() if result.is_valid(): print("Final valid input: " + str(datetime.datetime.at present())) print("Temperature: %d C" % result.temperature) print("Humidity: %d %%" % result.humidity) data = '\r\northward{\r\northward "m2m:cin": {\r\northward "cnf": "message",\r\north "con": "\r\n {\r\n \t \\"Temperature\\": \\"'+str(result.temperature)+'\\",\r\n \\"Humidity\\": \\"'+str(result.humidity)+'\\"\r\n url = 'https://platform.antares.id:8443/~/antares-cse/antares-id/your-awarding-name/your-device-name' headers = {'enshroud-control':'no-enshroud','content-type':'awarding/json;ty=4','x-m2m-origin':'Your-Acces-Key'} r = request.mail(url,headers=headers,information=data) time.sleep(2) Salve the file, then open up the Terminal window and type the following code:
cd DHT11_Python && python dht11_example.py then the display will appear as follows:
Effigy 12. Display on Terminal
The display shows that the sensor starts measuring temperature and humidity. Next, please check the data entered on the Antares Device that you lot have made before. If successful, the display on your device will look like this:
Figure 13. Brandish of Device on ANTARES
Source: https://www.antares.id/en/raspi-tutorial.html
0 Response to "Dht11 Failed to Get Reading Raspberry Pi"
Post a Comment