2

I am trying to read some information from Raspberry. This script can be read for all types of Raspberry. I will define them via Raspberry Profile.
A Raspberry Profile can be thought of as a template or as a type or classification of Raspberry. General characteristics of the type of Raspberry such as:
1 - name
2 - description
3 - IP address
4 - Location
5 - Type of data (some parameters that Raspberry has like supporting BLE, Wifi, several sensors, protocol...)

Are there any ways to read the profile of Raspberry or how could I do that?

Thank you


UPDATE:
The profile information of Raspberry will send to a server to manage. The server will then read these profiles and accept them into the server's network.

6
  • 1
    Hello and welcome -- What do you mean by "profile of Raspberry Pi 3"? Do you mean that some script that runs some commands themselves and save some information to a file?
    – M. Rostami
    Jan 29, 2020 at 11:47
  • Hello M.Rostami - Yes. I want to use a script (some commands) or a program (ex, python) to save some information to a file. I mean that the profile of Raspberry Pi 3 will provide some information which I said above. It looks like a way to manage Raspberrys information in my network.
    – JERLee
    Jan 29, 2020 at 13:29
  • Alright, and, where do you want to save this information? Do you wanna save simply on a location on all raspberry pis? There is some monitoring software and collect this information on another host. I mean, you install a monitoring server software on a computer and get data continuously from raspberry pis. If you want a simple one, python is the best choice and on the other hand, I can answer a question with some monitoring tools.
    – M. Rostami
    Jan 29, 2020 at 13:38
  • Thank you a lot M.Rostami. The profile information of Raspberry will send to a server to manage. The server will then read these profiles and accept them into the server's network. If you can, you can suggest some monitoring tools for me? Thank you so much
    – JERLee
    Jan 29, 2020 at 15:01
  • Alright, I've done it times ago, now, I'm gonna test then add an answer. Please add this new information to the question body.
    – M. Rostami
    Jan 29, 2020 at 15:02

2 Answers 2

2

There is no way to get a "profile" with exactly the information you want. But you can use different available commands to gather the information into a file. There are many commands and possibilities. Here are only some examples:

rpi ~$ cat /etc/os-release > profile
rpi ~$ ip address >> profile
rpi ~$ iw dev wlan0 info >> profile
rpi ~$ uname --all >> profile
rpi ~$ lsblk >> profile
rpi ~$ df -h >> profile
rpi ~$ sudo parted /dev/mmcblk0 print free >> profile
rpi ~$ cat /proc/cpuinfo >> profile
rpi ~$ cat /proc/meminfo >> profile

... and much much more. It depends what you want to know. This is a very simple and raw example. You will find the information from the commands in the file profile. You can modify the output of the commands with its options or with the filter grep.

Here is a short bash example script how you can make your profile. Create a file profile.sh with this contents:

#!/bin/bash

echo profile of $(tr -d "\0" < /sys/firmware/devicetree/base/model)
echo -----------------------------------------------------------
echo Serial number: $(tr -d "\0" < /sys/firmware/devicetree/base/serial-number)
echo Name: $(hostname)
echo Full name: $(hostname --all-fqdns)
echo Interfaces:; ip -br addr

Make it executable with chmod +x profile.sh and execute it:

rpi ~$ ./profile.sh
profile of Raspberry Pi 4 Model B Rev 1.1
-----------------------------------------------------------
Serial number: 10000000cd0297b1
Name: raspberrypi
Full name:
Interfaces:
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             192.168.50.137/24 fe80::77c0:a4bd:e655:5427/64
wlan0            DOWN

If you need other information just ask for it. I'm sure you will get immediately an answer.

5
  • Thank you, Ingo. I mean that I want to get the information which Raspberry has (some characteristics such as supporting Wifi, BLE, some sensor, some protocol...). It looks like the profile of a person (ID, name, full name, some skills of that persorn...)
    – JERLee
    Jan 29, 2020 at 15:38
  • 1
    @JERLee Yes, that's all no problem. You can get all information you want but you cannot expect to get the information just formated as you like it. You have to take a bit effort to format it for your needs.
    – Ingo
    Jan 29, 2020 at 20:10
  • @JERLee I have added a short bash example script to the answer for formated output
    – Ingo
    Jan 29, 2020 at 21:42
  • Thank you so much - @ Ingo. I have a question. If I use some sensors attaching with Raspberry, I can read some information about sensors? For example Raspberry Pi 4 Model B Rev 1.1 has a DHT11 sensor that provides digital temperature and humidity readings.
    – JERLee
    Jan 29, 2020 at 22:56
  • @JERLee The computer doesn't know it by itself. You always have to check for the sensor, but if you find it then you are free to output a nice message as shown in your comment above. This is conditional programming with if statements.
    – Ingo
    Jan 30, 2020 at 1:04
1

You can save all the information about Raspberry Pis on a server with SNMP. At first, let take a look and this network protocol.

What is SNMP?

Simple Network Management Protocol (SNMP) is an Internet Standard protocol for collecting and organizing information about managed devices on IP networks and for modifying that information to change device behavior. Devices that typically support SNMP include cable modems, routers, switches, servers, workstations, printers, and more.

So, now you know that you should install some packages to make your Raspberry Pis as an SNMP agent. After that, they can answer SNMP requests of the SNMP server which is another host (a Windows or a Linux box). On the other words, the host can get the status of all your raspberry pis.


Install packages:

sudo apt-get update
sudo apt-get install snmp snmp-mibs-downloader  
sudo apt-get install snmpd

SNMPd Configuration, The configuration file is located at /etc/snmp/snmpd.conf. Make sure you are editing the snmpd.conf file and not the snmp.conf file:

sudo nano /etc/snmp/snmp.conf

Change lines like it:

view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1

 rocommunity public  default    -V all

 rocommunity6 public  default   -V all

Open the daemon’s configuration file with sudo privileges:

sudo nano /etc/snmp/snmpd.conf

Change lines like it:

# Listen for connections from the local system only
# agentAddress udp:127.0.0.1:161
# Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161  

Start the services:

sudo service snmpd start

Test the SNMP on the local raspberry pi as a test:

snmpwalk –v2c –c public 127.0.0.1 .1.3.6.1.2.1.25.1.1  

You would see the result like it:

SNMPv2-MIB::sysORUpTime.1 = Timeticks: (3) 0:00:00.03  

Which tells you the uptime of the device. Now you can install snmpd packages and run snmpwalk command to gather this configured raspberry pi uptime status from the host. Also you need to change 127.0.0.1 to that raspberry pi IP address or Domain name.

There is a lot of information that you can get from the SNMP server to SNMP agent like, System hostname, IP address, number of packets, storage capacity, UUID, serial number, mac address, etc. Just search about that and add the OID root to the snmp.conf then request that OID value.

In addition, you can install a featured SNMP server on your host to monitor your raspberry pis. OpenNMS is one of them but I suggest PRTG. You can even create your own snmp OIDs (can be the output of a command) to send for the SNMP server as you said (5 - Type of data ).

In conclusion, you can send raspberry pi pre-arranged information or self-arranged (ANY information you want) to a host which can be a Linux or Windows PC.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.