Skip to content

πŸ”Š IoT sound data recording, transfer, storage, and website graph output

License

Notifications You must be signed in to change notification settings

roman-bezusiak/Sound-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

82 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sound project

πŸ“₯ Installation instructions

Required software:

  1. RPi files ( RPi)

  2. Server files (Server)

  3. PuTTY ( MOC)

  4. Curl library ( RPi)

πŸ›  Configuration instructions

Required equipment:

  1. Raspberry Pi, Model 3B (further: RPi)

  2. External USB sound card (further: sound card)

  3. Microphone, 3.5 mm headphone jack plug (further: mic)

  4. "RJ45" Ethernet cable (further: e-cable)

  5. Power supply for the RPi (one of the following):

  6. Server

  7. Main operating computer (PC, laptop, etc.; further: MOC)

Optional (for testing sound recording quality):

Sound playing device, 3.5 mm headphone jack plug (further: dynamic)

Required equipment set-up:

  1. Connect the RPi to the Internet using the e-cable

  2. Connect the sound card to the RPi

  3. Connect the mic to the sound card

  4. Connect the RPi to the power supply

Optional (for testing sound recording quality):

Connect the dynamic to the sound card

Required software settings:

  1. Check whether Curl library is already installed on the RPi by running the following command:
~$ ls /usr/include/curl

If it is not, install it by running the following commands:

~$ sudo apt-get update
~$ sudo apt-get install libcurl3
~$ sudo apt-get install libcurl4-openssl-dev
  1. Set the sound card as Default by performing the following steps:

Run:

~$ lsusb

The following should be seen:

Bus 001 Device 004: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Run:

~$ sudo nano /etc/asound.conf

Contents of asound.conf should be changed to the following:

pcm.!default
{
	type plug
	slave
	{
		pcm "hw:1,0"
	}
}

ctl.!default
{
	type hw
	card 1
}

Go to the home directory of the RPi.
Run:

~$ nano .asoundrc

Contents of .asoundrc should be identical to ones of asound.conf.
Run:

~$ alsamixer

In the opened menu sound card should be seen as a default.

	Card: C-Media USB Headphone Set
	Chip: USB Mixer
	View: F3:[Playback] F4: Capture  F5: All
	Item: Headphone [dB gain: -20.13, -20.13]

Adjust sound settings of the mic and dynamic according to your preferences:

	   β”Œβ”€β”€β”           β”Œβ”€β”€β”
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚  β”‚
	   β”‚  β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”‚β–’β–’β”‚           β”‚β–’β–’β”‚
	   β”œβ”€β”€β”€           β”œβ”€β”€β”€
	   β”‚OOβ”‚           β”‚MMβ”‚
	   β””β”€β”€β”˜           β””β”€β”€β”˜
	  19<>19           52
	Headphone         Mic         

  1. alsa-utils should be version 1.0.25, in order to make it so, the following steps should be performed:

Run:

~$ sudo nano /etc/apt/sources.list

Add the following line at the end of sources.list:

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi

Run:

~$ sudo apt-get update
~$ sudo apt-get install alsa-utils=1.0.25-4

Reboot (if necessary).

Optional test of the sound quality:
Run:

~$ arecord -r44100 -c1 -f S16_LE -d5 test.wav

Connect dynamic to the sound card. Run:

~$ aplay test.wav

οΈοΈοΈοΈοΈβš™οΈ Operating instructions

Algorithm

I. Mandatory part:

  1. Recording 1 second of audio into test.wav file using RPi

  2. Outputting corresponding data in the console window (one of the following):


	β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
	β”‚ MOC           β”‚  β†’  (commands)      β†’  β”‚ RPi            β”‚  ↔  β”‚ Sound card      β”‚
	β”‚     (PuTTY)   β”‚  ←  (sound          ←  β”‚      (sound.a) β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
	β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      info / graph)     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        ↕         ↕
	                                                                β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
	                                                                β”‚ mic β”‚ β”‚ dynamic β”‚
	                                                                β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

II. Optional part (COMM mode):

  1. Sending FastDB (8 decibel values recorded once in every 125 ms) data to the server

  2. Storing the data on the server side (both of the following):

    • All the data with attached dates in sound_log.txt file
    • Last received 8 pieces of sound data in last_line.json file
  3. Outputting the last obtained data on the responsive webpage real-time chart


	............................................................................

	β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
	β”‚ RPi             β”‚  β†’  (sound data)  β†’  β”‚ Server               β”‚
	β”‚       (sound.a) β”‚                      β”‚          (sound.php) β”‚
	β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β”‚      (soundGraph.js) β”‚
	                                         β”‚         (sound.html) β”‚
	β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
	β”‚ MOC             β”‚   ←   (sound graph)    ↲
	β”‚       (browser) β”‚
	β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               

Web site graph example

Choosing the operating modes

There are some preset values ruling conditional compiling in the RPi files:

  1. DEBUG mode - off ( non-DEBUG mode or DEBUG undefined)
  2. UNICODE mode - on (UNICODE mode or UNICODE defined)
  3. COMM mode - on (COMM mode or COMM defined)

DEBUG / non-DEBUG mode

The DEBUG constant is defined in sound.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:

#define DEBUG // Conditional compiling

UNICODE / non-UNICODE mode

The UNICODE constant is defined in screen.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:

#define UNICODE // Conditional compiling

COMM / non-COMM mode

The COMM constant is defined in comm.h. In order to set it off / on, add / remove two slashes (//) respectively in the beginning of the following line:

#define DEBUG // Conditional compiling

Setting the servers URL address on the RPi side

When COMM mode is set, one should change the URL address in comm.h file in the following line:

#define URL "http://your.server.com/.../sound.php"

Launching

  1. Launch the RPi

  2. Connect to the RPi via PuTTY

  3. Make the object files and the sound.a application by running the following command:

~$ make
  1. Run the application by entering the following command:
~$ ./sound.a
  1. Go to the server's URL in the browser on the MOC

In order to stop the program, press Ctrl + C in the PuTTY console window.

πŸ—ƒ File manifest

List:

  • RPi (8):

    • .c files (4):
      • comm.c
      • main.c
      • screen.c
      • sound.c
    • .h files (3):
      • comm.h
      • screen.h
      • sound.h
    • Other files (1):
      • makefile
  • Server (5 (7 including optional ones)):

    • Front-end files (2):
      • sound.html
      • soundGraph.js
    • Back-end files (3):
      • last_line.json
      • sound.php
      • sound_log.php
    • Optional files (2):
      • sound_log.txt
      • last_line.json
  • Other (3):

    • README.md
    • LICENCE
    • web_site_graph_example.png

Total: 16 files (18 including optional ones)

Remark

Even if there are no optional files, they will be created when the data transmission from RPi to the server starts. But, if one runs the program without data transmission from RPi, the chart will be drawn only if there is last_line.json file with valid data.

Valid last_line.json data example:
{"data":"124.00;219.49;317.29;412.53;389.72;256.49;134.82;192.13;"}

βš–οΈ Copyright and licensing information

This project is licensed under the GNU General Public License. See the LICENSE file for details

⚠️ Known bugs, problems and troubleshooting

"The graph is not updating on the site"

Problem:

There is only one graph state on the site and it does not change.

Solution:

  1. Check the set-up
  2. Check whether the sound.a is running
  3. Refresh the web page

"There are some weird symbols changing in the console window"

Problem:

The symbols used as bars are some weird ones and completely do not seem to have a bar form. The console does not recognize the UTF-8 symbol U+2590 used as a bar in screen.c file.

Solution:

Set the console's character set to UTF-8 or, if the console does not support UTF-8, set non-UNICODE mode.

PuTTY solution:

  1. Go to the console settings (choose either way)

    • PuTTY - Configuration window can be reached when PuTTY is launched
    • PuTTY - Reconfiguration window can be reached by right-clicking on the top bar of the PuTTY window
  2. Window (window's left side tree)

  3. Translation (window's left side tree)

  4. Remote character set (window's right side)

  5. Choose UTF-8 (drop-down list)

πŸ‘ Credits and acknowledgments

Authors:

Used resources:

Used code: