Raspberry Pi as mosca mqtt broker,Node-Red and MongoDB - python

I'm working on a school project and I'm a little bit overwhelmed. Is the first time that I work with mqtt service and Node-Red. In the structure of the project I have a Raspberry Pi communicated through gpio with a dht11 sensor, I want to communicate the RPi with my VPS where Node-Red is hosted. Finally this Node-Red working as suscriber in mqtt service has to save the data of measures in a MongoDB database and show the data in a graph. Can someone explain me how to communicate RPi and Node? RPi can work as broker and client in mqtt at the same time? Sorry for my English I'm learning.

MQTT is a client (subscriber/publisher) server (broker) process.
Both the broker (mosca) and the client can run on a computer (RPi, VPS).
Check that the RPi is the best place for the broker. Your VPS (virtual private server) must have a connection to the broker. If the RPi is behind a firewall in your private network, you need to open an inbound port!

Related

How to subscribe to a Raspberry Pi Broker in a different network using Mosquitto MQTT?

I did this project
https://diyi0t.com/microcontroller-to-raspberry-pi-wifi-mqtt-communication/
But in that project, the Raspberry Pi is both the Broker and Subscriber. I would like to Subscribe my Raspberry Pi at work, to my Raspberry Pi Broker at home.
I tried making my home Pi a static IP address, but it keeps timing out.
How can I connect from a different network? I just want to be able to run the Python code and receive the readings from the sensor that the Pi at home has.
Thank you.

Hide Database Credentials in Python Code on Raspberry Pi

I want to use Raspberry Pis to communicate collected Data via Python (Modbus TCP and RTU) scripts to a Database. These scripts are constantly running on the Pi and are connected to the Products where the data is coming from.
Consequently, we have to ship the already set up Raspberry Pi to the Customer. Now the Problem occurs, that the Database Credentials are stored in the Python Scripts running on the Raspberry Pi.
Is there a possibility to overcome this Problem?
Naive solution: Store database credentials on your server (or somewhere on internet) so every time Raspberry Pi run the script, it connect to the server to get the credentials first.
My recommended solution: Create an API (may be web API) to communicate with database and Rasp Pi only work with this API. By this way, the client side doesn't know about database's credentials and some private things you want to hide also.

How to connect an iot device to a django server which is in my pc?

I am working on an IoT project, where I have built my device using a Raspberry Pi. Now I want to send data captured by my device to my back-end server, which is a Django server. Also sending data should be done real-time. I am using a GSM module to connect the device to internet. The Django server is in my local PC.
How can I establish the connection between my Raspberry Pi and Django server?

Raspberry Pi custom commands in a scripting language through tcp/ip connection

I'm currently working on a project that requires me to control a step motor using a raspberry pi. I finished the motor control part of the raspberry pi, but I am not really sure on how to continue on the tcp/ip connection part of the project.
I am meaning to connect a client through the tcp/ip connection and letting the client upload a code that lets the client control the motor, in which there should already be custom commands implemented (e.g. "clockwise ": turns the motor a number of steps clockwise. "set 1": sets the gpio pin to 1, and etc.)
I apologize because my knowledge in raspberry pi and tcp/ip connections are really limited.
Can someone point me a way in the right direction? Thanks in advance.
If you are looking for a scripting solution you can do TCP/IP part using ssh. Client can use ssh to log into the RPi and run the commands. It can use scp for pushing updated code/script.
For automating you can look into Pexpect that lets you script your steps.

How to receive data (CAN bus messages from an application on PC) via TCP into a Web Server running on Raspberry Pi?

I want to receive data into a local web server that I have created using Raspberry Pi. It is not connected to the internet. I want to know if it is possible to receive data from an application on a Windows PC that sends via TCP protocol. The web server is an Apache server. I can specify the web server address and port number in the application that sends the data.
I am a newbee to this and I just know what tcp, http etc means. I do not know them in detail so I am finding it hard to understand related articles on the internet. Can someone please help me with some code snippets on how to set the web server in raspberry pi so that I can receive the data? Either display it on the web server page or extract the data somewhere using Python or C#. I am also open to using a Raspberry Pi with Windows IoT image instead of Jessie to do the same.
With Windows IoT you can start with Hello blinky sample that create a simple Web Server in Python.
Also, restup create a Web server in C# you can reference. This is the tutorial help you set up the code lines. I test TCP packets receiving on Raspberry Pi 3 with this web server, it works.
Hope it is helpful for you.

Categories