Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is this for loggin noise? #3

Open
MisterMakerNL opened this issue Sep 24, 2019 · 41 comments
Open

Is this for loggin noise? #3

MisterMakerNL opened this issue Sep 24, 2019 · 41 comments

Comments

@MisterMakerNL
Copy link

Hey,
I also have this meter, first I was just going to use Windows. But the lack of any autmated logging is a bit worrying.
Can you use this to log the data? Can I send it to a webserver?

@davegudge
Copy link
Contributor

davegudge commented Sep 24, 2019

I've used @ciembor 's work to successfully connect a gm1356 to a device running Ubuntu server.

Once connected you should be able to run bin/gm1356 and see a log output of the reading from the device.

I've used this repository to gain access to the output, then build upon that to store the output in a database, so I can then report on the data:

raw

5seconds

compare

@MisterMakerNL
Copy link
Author

owh that is nice! The local government decided to place a disco next to my house at 100mtr. I asked them to come and measure the sound, they told me it was to expensive. Now I am here.... I know it is not a valid measuring, but should be enough to make them come and measure themself.
Is it possible for me to get such a system you made working? I only did small amount of linux work on my pi's.

@ciembor
Copy link
Collaborator

ciembor commented Sep 24, 2019

@HaasNL2 I started work on system for measuring environmental noise. I calculate Equivalent Continuous Sound Level (LAeq) for each hour based on Polish indicators. I think they should be similar or the same in all EU countries.

It's here: https://github.com/ciembor/dobra-noc

I don't have currently time for development. I have to work on commercial project. But it looks that my friend will continue it. The goal is to have a platform with clients installed on Raspberry PI. Currently it's standalone app, so you can connect sonometer to the laptop, run Dobra Noc (Good Night :)) and the results will be stored to the database. In the same time it is possible to display them in a browser for each recorded hour.

Feel free to test it, report what you need and create some GH Issues. Or maybe even pull requests? If you want to learn some Ruby / Vue.js, we need some contribution. It's not rocket science and it looks there are many people in a similar situation to yours. I found a lot of them in my city already :(.

@davegudge
Copy link
Contributor

davegudge commented Sep 24, 2019

Funny enough, I have this setup for a similar purpose. The local council have said that the graphs/charts on thier own could not be used as evidence, however, they have sent out diary sheets to complete, and they said the charts will complement the diary entries.

I've used a Ruby on Rails app to do the charts above. Would that be of any use to you? As I could look to move the code into a public repos, however, it would require some knowledge to get it up and running.

An alternative option (which I did first) would be to capture the output from bin/gm1356 into a file on the server. You could then take that data and use an online charting tool to generate a graph. There's lots out there, I used https://chart-studio.plot.ly/create/#/

EDIT:

@HaasNL2 I forgot to mention that the local coucil have not shown much interested in doing anything, however it may be worth searching for the 'Environmental Health' department within the council, as they have been very helpful in my area. They are the ones who have sent out diary sheets etc.

@ciembor
Copy link
Collaborator

ciembor commented Sep 24, 2019

@davegudge maybe we could merge our apps into one and make it useful for more people?

@MisterMakerNL
Copy link
Author

MisterMakerNL commented Sep 24, 2019

Nice work all of you I need some time to process all that information.
I am pretty good with 3D printers and 3D modeling so I tried to help out too with my skills, and made a casing/mount for the GM1356 I just uploaded it here:
https://www.printables.com/model/6631-gm1356-holder (updated link)
It is now hanging on the front of my building.

About my issue with the council.
I asked them to come and place a fixed dB measuring, they said they only send a guy to come measure when there are complains. But the official complains get published online, which they can read and act on.
Also the last 3 measurements failed, because of background noises. (coming from the visitors of the disco) Which you van probably average off when you have enough data.

The guy who was responsible about the measuring, said to me it was to expensive to mount a fixed measuring device. And I then asked him how much it would cost. Instead of giving me a euro figure he told me "it didn't work that way". I now assume he didn't even bothered to check the costs. He told me that in a phone call which I was recording and now I have made an official complain against him. Fun times!

@ciembor
Copy link
Collaborator

ciembor commented Sep 24, 2019

@HaasNL2 That's awesome, I was thinking how to protect it from rain :).

@davegudge
Copy link
Contributor

@ciembor It's certainly an option.

I calculate Equivalent Continuous Sound Level (LAeq) for each hour based on Polish indicators.

This sounds interesting. I've had to do some research into sound/decibels etc I kind of feel the graph should be a reverse logarithmic to give a more accurate representation of the increasing levels of sound. e.g. the y-axis would be scaled like this:

WhatsApp Image 2019-07-12 at 12 07 39

I couldn't find any charting tools to create that, so I did experiment with colours:

WhatsApp Image 2019-08-30 at 18 30 27

@HaasNL2 The case is really cool. Much better than the piece of plastic I am currently using!

IMG_7431

@davegudge
Copy link
Contributor

@ciembor I think https://github.com/ciembor/dobra-noc might be private as it presents a 404.

@ciembor
Copy link
Collaborator

ciembor commented Sep 24, 2019

@davegudge I use Chart.js and they also don't have it. They have only logaritmic scale. But the numbers don't lie and are more important as an evidence.

You are right, I made it public :).

@davegudge
Copy link
Contributor

I've been using Chart.js too (via chartkick), the coloured chart was experimenting with highcharts.

You are right, I made it public :).

RoR and 5.2 too 👍 I'll have to find some time to take a look. The rails app I've created so far is over on bitbucket, it was hosted before github allowed private repos for free. I'll look to move it over onto github and make it public too. It's still on 5.1 at the moment 😢 Never enough time to spend working on these side projects.

@ciembor
Copy link
Collaborator

ciembor commented Sep 24, 2019

@davegudge Yes, not enough time for side projects and writing tests for them :D.

@davegudge
Copy link
Contributor

and writing tests for them

🤣

@ciembor
Copy link
Collaborator

ciembor commented Oct 17, 2019

@davegudge did you succeed to display graph in inverted logarithmic (exponential) scale? I found this: https://github.com/holtalanm/chartjs-exponential-scale
But I have no idea if it works. It would be nice to write chartjs plugin for this.

@davegudge
Copy link
Contributor

@ciembor I haven't managed to invert a logarithmic scale so far, and tbh, I haven't looked into it (again) since we discussed above.

When I did look into it, I had a play with Logarithmic axis in highcharts, however, this obviously didn't present the data in the way required for a db scale. There is a option to invert the y-axis, however, that still doesnt acheive the desired affect, I ended up with an upsidedown chart 😆

Nice find on the plugin above. I think that could be used as a based to create a scale that could be used for db scale. I don't think it's possible to use logarithmic in it's standard form, but I could be wrong!

@stoney321
Copy link

stoney321 commented Oct 20, 2019

Hi, i also have a gm1356 sound meter and was trying to run this on a ubuntu server.
I have very limited knowledge when it comes to linux and programing, I have managed to get it installed but once i run gm1356 it displays the output for about 10-30 seconds then errors with TRANSFER_ERROR (LIBUS::ERROR_IO).

EDIT: Im running ubuntu server in vmware which seems to be causing the error, if i pass the gm1356 through vm remote console it works fine.

What would be the best way to record the output to a file?

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

@stoney321 What do you mean by output? Records with sound pressure levels? If you think about recording sound, we are going to connect a microphone to our RaspberryPI and record the loudest parts.

The easiest way to save records is to run ./gm1356 >> records.log

If you need more sophisticated format, you could load the library in your ruby script and pass a block. I think I should add the usage section to the readme.

@stoney321
Copy link

@ciembor I do just need to save the records as a log file as you have shown. 👍
The reason for the log file is so i can import it into Home Assistant and maybe try to display graphs etc.
Im still having problems with it crashing and cant seem to get it to run for more than 30 seconds. I think it may be power related? Im going to try a dedicated psu today rather than usb.

@davegudge
Copy link
Contributor

@stoney321 I was having issues where by the output was stopping after a random duration, but no error was output. I believe this is because the process is using a Thread and by default, an exception will not be thrown if the thread errors.

Perhaps try using the modification I have suggested in #2 i.e. if an error occurs whist processing, pass it back from the thread to the process that created the thread. Hopefully you'll then get an handle on the issue?

@stoney321
Copy link

stoney321 commented Oct 22, 2019

HI @davegudge i did have a look at that but i have no clue what to do with it. Do i need to modify a file? or create a new? My knowledge is very limited on this.

EDIT: Just tried dedicated psu and still errors :(

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

@davegudge I will merge it to master and check it later

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

@davegudge @stoney321 I published version 0.0.4 with pull request proposed by @davegudge, but I didn't test it yet ;). Let me know if it works better.

@davegudge
Copy link
Contributor

I've added an additional comment to the PR.

You should not find any difference if things are running as expected, but with the change in the PR, you should find the root cause (exception) is output if the process fails.

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

I think I will have to rewrite the code, the problem is in data synchronization. I should read data from device to the buffer and then access it from a buffer instead of accessing packets directly. Packets are sometimes corrupted, because they sometimes have not proper length (when data is split in two packets).

@davegudge
Copy link
Contributor

the problem is in data synchronization

That does make sense based upon some of the exceptions I've seen. Rather than trying to fix it, I took the approach of "if it failed, just try it again, and again until is worked!" 😆

@stoney321
Copy link

just installed version 0.0.4 but still the same problem, i think i had already modified end.abort_on_exception = true.
@davegudge, i wouldn't know even where to start with your workaround

@davegudge
Copy link
Contributor

same problem

which is:

errors with TRANSFER_ERROR (LIBUS::ERROR_IO)

right?

@stoney321
Copy link

correct

@davegudge
Copy link
Contributor

Just to confirm, the abort_on_exception = true will not fix the issue you are having, it was just to present the error back to screen.

I then build upon that (from within a separate Ruby on Rails application) to say:

run GM1356, if it errors, run GM1356, if it errors, run... etc

@stoney321
Copy link

I kind of got what you were doing, just not a clue about automatically re-running gm1356 when it errors.
I know little bit of linux/ubuntu but nothing of Ruby and Rails. I keep having to google everything

@davegudge
Copy link
Contributor

davegudge commented Oct 22, 2019

Running directly from the terminal, perhaps you could do something like https://superuser.com/a/569595

EDIT:

I was thinking the executable was a bash, it's ruby which does make life easier!

@stoney321
Copy link

stoney321 commented Oct 22, 2019

Would it be worth me looking to use ruby on rails for this?
Thanks, will have a look

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

No need to know Ruby on Rails, Ruby is enough, and it's quite nice language to learn :). If you want to learn it a bit I can send you some resources, this script should be quite easy. If you don't I can write it for you but I don't know when I will have time. We can even meet on google hangouts and I will show you how I write it, so you will know why it works and how it works :).

you need to:

  1. Create new project with bundler (Gemfile) and include this gem in a Gemfile
  2. run bundle install
  3. create a file with the ruby script
  4. make it executable
  5. require this gem in your script
  6. Check how /bin/gm1356 works, copy and paste this code
  7. Instead of printing messages, save each record to the file

Then you can handle errors using rescue

@ciembor
Copy link
Collaborator

ciembor commented Oct 22, 2019

device = GM1356::Device.new(options)

begin
  device.read do |record|
    puts record.to_s
  end
rescue Exception # rubocop:disable Lint/RescueException
  device.close
  raise
end unless options[:just_set]

device.close

This is the part from a /bin/gm1356 you are interested in.

If there is an exception I close the device. But you can handle this exception however you want. And you can save it to the file directly instead of printing it.

@davegudge
Copy link
Contributor

I haven't tested this but as @ciembor suggested, simply modifying the /bin/gm1356 would be the easiest approach.

https://github.com/davegudge/gm1356/commit/f80f19f5e9d36e5685a69da50ca9080928795864

^ I've moved the logic outlined above into a method, and upon failure, instead of raising the exception (causing an exit), it's simply output, and the method is called again.

It may be a good stating point for what you're looking to achieve.

@stoney321
Copy link

Thanks guys, its giving me something to look at

@davegudge
Copy link
Contributor

@MisterMakerNL
Copy link
Author

Pff I am waaaaaaaaaaaaaaaay over my head here, trying this out.
Been working on this like 2 days now to get the webserver running.
I finally made it too it being installed.
But ended uop with a Cannot GET /
And a gpio pi error. While I installed without pi.
I am pretty much lost now.
The usb driver works great get good readings.
But at the moment I cannot do anything with the readings.

afbeelding

@davegudge
Copy link
Contributor

If running via an app is a bit tricky at the moment, maybe a good starting point is to record the output above to a .csv file, and then create a chart via an online charting tool. A bit manual, but that's were I started when using gm1356

@tyl0re
Copy link

tyl0re commented Jul 14, 2020

I made a Pull request, changing puts to print makes the Output Parsable.

I make a Box recording the DBA, and when the DBA is over some Value the Box plays an mp3 "To Loud". I use it for education. Our Children forget not to shout at each other. So the Box remember them to keep Quit

I Start it with :
/usr/local/bin/gm1356 2>/dev/null 1>/var/log/sound.log&

And an Python Script to react on Values from the Log:

#!/usr/bin/python3
import re
import os
from gtts import gTTS
from sh import tail
import subprocess
import time

filename="/tmp/zulaut.mp3"
for line in tail("-f", "/var/log/sound.log", _iter=True):
    m = re.search('SPL: ([0-9\.]+)dBA', line)
    if (float(m[1])>70) :
       print(line)
       print ("Zu Laut")
       print(m[1])
       tts = gTTS('Zu Laut',lang='de')
       tts.save(filename)
       subprocess.call(["/usr/bin/play", "--volume","5", filename])
       os.remove(filename)



@ciembor
Copy link
Collaborator

ciembor commented Jul 20, 2020

@tyl0re It's very nice to hear that you found such interesting usecase! I didn't expect too many people will use this driver and how many possibilities it gives :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants