Speaker function ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ILoveIOT
Normal user
Posts: 44
Joined: 01 Nov 2015, 10:54

Speaker function ?

#1 Post by ILoveIOT » 02 Dec 2015, 11:29

Maybe its easy (don't know) to implement to have a speaker function so you get a acknowledge from Domoticz, with some different tones, for different functions.

http://<ESP IP address>/control?cmd=spk,<pin>,1-2-3 etc

ambassadoro
Normal user
Posts: 40
Joined: 17 Nov 2015, 15:58

Re: Speaker function ?

#2 Post by ambassadoro » 03 Dec 2015, 14:28

Could be done with a piezo like this and pwm:
Ebaybuzzer.

ILoveIOT
Normal user
Posts: 44
Joined: 01 Nov 2015, 10:54

Re: Speaker function ?

#3 Post by ILoveIOT » 03 Dec 2015, 16:22

Yes,..this piezo buzzer (speaker) I mean, is it already working ?

ILoveIOT
Normal user
Posts: 44
Joined: 01 Nov 2015, 10:54

Re: Speaker function ?

#4 Post by ILoveIOT » 07 Dec 2015, 19:33

Thank you for the lead, http://192.168.50.194/control?cmd=Pulse,14,1,100 did the trick for me, single tone do, but it does the job ;)

With PWM you have to send a off command as well, pulse stops after 100ms, in this case.

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#5 Post by Marteln » 30 Sep 2016, 23:22

I add some code to _P001_Switch, now I can play tone with any frequency: http://192.168.3.57/control?cmd=tone,14,330,2000 - on port 14 play E1 two seconds.

and

Or play RTTTL melody: http://192.168.3.57/control?cmd=rtttl,14,Bach - Prelude In C Minor:d=8,o=5,b=180, c6, b, c6, p, g, g-, p, f, b, c6, p, d6, p, g, p, c6, b, c6, p, d6, p, f, g, g-, 4p, g, f, 4d-

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Speaker function ?

#6 Post by moelski » 01 Oct 2016, 06:57

Hi Marteln,
I add some code to _P001_Switch
can you share the code ?
regards
Dominik

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#7 Post by Marteln » 01 Oct 2016, 10:15

Here it is. There are two new function:

void play_rtttl(uint8_t _pin, char *p )
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)

and two if statements:


if (command == F("rtttl"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
char sng[1024] ="";
string.replace("-","#");
string.toCharArray(sng, 1024);
play_rtttl(event->Par1, sng);
setPinState(PLUGIN_ID_001, event->Par1, PIN_MODE_OUTPUT, event->Par2);
log = String(F("SW : ")) + string;
addLog(LOG_LEVEL_INFO, log);
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_001, event->Par1, log, 0));
}
}

if (command == F("tone"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
tone(event->Par1, event->Par2, event->Par3);
setPinState(PLUGIN_ID_001, event->Par1, PIN_MODE_OUTPUT, event->Par2);
log = String(F("SW : ")) + string;
addLog(LOG_LEVEL_INFO, log);
SendStatus(event->Source, getPinStateJSON(SEARCH_PIN_STATE, PLUGIN_ID_001, event->Par1, log, 0));
}
}

In RTTTL definition is used character "#", but it must be encoded in URL, so I use "-".
Attachments
_P001_Switch.rar
(3.51 KiB) Downloaded 323 times

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#8 Post by Marteln » 01 Oct 2016, 10:22

I needed a wireless doorbell. The first version was with the UM66, but it meant only one meody ...

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Speaker function ?

#9 Post by tozett » 02 Oct 2016, 08:25

wonderful addition.

hi dev,
are you listening here?

can it go into the main development branch?

(or someone good in coding make a plugin? moelski? :mrgreen: )

:mrgreen:

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#10 Post by Marteln » 02 Oct 2016, 08:48

tozett wrote:wonderful addition.

hi dev,
are you listening here?

can it go into the main development branch?

(or someone good in coding make a plugin? moelski? :mrgreen: )

:mrgreen:

Yes, it can. No problem.

User avatar
moelski
Normal user
Posts: 161
Joined: 31 Aug 2016, 06:33
Location: Germany - NRW
Contact:

Re: Speaker function ?

#11 Post by moelski » 02 Oct 2016, 10:44

Hi tozett !
can it go into the main development branch?
(or someone good in coding make a plugin? moelski? :mrgreen: )
Working on my Candle Plugin ;)

But this is more an Actor and not a Sensor ...
But anyway ... Making a stand alone "tone" plugin should be straight forward ...
regards
Dominik

rol-rider
Normal user
Posts: 43
Joined: 02 Oct 2016, 12:36

Re: Speaker function ?

#12 Post by rol-rider » 02 Oct 2016, 14:37

Great idea,
I wanted to test,
_P001_Switch.rar
it does not compile.

Code: Select all

296  log = String(F("SW   : GPIO ")) + String(event->Par1) + String(F(" Set PWM to ")) + String(webreq);

exit status 1
'webreq' was not declared in this scope
thank.

sorry I do not speak English!
sorry for my English ! i use google translat.

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#13 Post by Marteln » 02 Oct 2016, 15:35

rol-rider wrote:Great idea,
I wanted to test,
_P001_Switch.rar
it does not compile.

Code: Select all

296  log = String(F("SW   : GPIO ")) + String(event->Par1) + String(F(" Set PWM to ")) + String(webreq);

exit status 1
'webreq' was not declared in this scope
thank.

sorry I do not speak English!
Oh, sorry!

I sent older version :o

This is the correct.
Attachments
_P001_Switch.rar
(3.5 KiB) Downloaded 342 times

rol-rider
Normal user
Posts: 43
Joined: 02 Oct 2016, 12:36

Re: Speaker function ?

#14 Post by rol-rider » 02 Oct 2016, 16:43

Thanks,

I still managed to use "tone"

in rules:

Code: Select all

On BP#BP do
     tone,14,435,600
     tone,14,580,600
     tone,14,435,600
     tone,14,580,600
     tone,14,435,600
     tone,14,580,600
     tone,14,435,600
     tone,14,580,600
endon
French police siren


but "rtttl" ???
I test the new file.
sorry for my English ! i use google translat.

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#15 Post by Marteln » 02 Oct 2016, 17:10

rol-rider,

you have to replace "#" with "-" or urlencode string.

rol-rider
Normal user
Posts: 43
Joined: 02 Oct 2016, 12:36

Re: Speaker function ?

#16 Post by rol-rider » 02 Oct 2016, 18:20

Great ! it works !

this is the ":" I forgot!

Code: Select all

http://192.168.0.3/control?cmd=rtttl,14:d=8,o=5,b=180,c6,b,c6,p,g,g-,p,f,b,c6,p,d6,p,g,p,c6,b,c6,p,d6,p,f,g,g-,4p,g,f,4d-
beautiful melody
sorry for my English ! i use google translat.

Marteln
New user
Posts: 7
Joined: 30 Sep 2016, 22:42

Re: Speaker function ?

#17 Post by Marteln » 02 Oct 2016, 20:55

rol-rider wrote:Great ! it works !

this is the ":" I forgot!

Code: Select all

http://192.168.0.3/control?cmd=rtttl,14:d=8,o=5,b=180,c6,b,c6,p,g,g-,p,f,b,c6,p,d6,p,g,p,c6,b,c6,p,d6,p,f,g,g-,4p,g,f,4d-
beautiful melody
Correct syntax is : rtttl, pin,name_of_melody:duration,octave,beat,notes..........


Somewhere use ":" after beat, somewhere ","... I didnt try ":", maybe work, maybe not.
https://en.wikipedia.org/wiki/Ring_Tone ... r_Language

rol-rider
Normal user
Posts: 43
Joined: 02 Oct 2016, 12:36

Re: Speaker function ?

#18 Post by rol-rider » 03 Oct 2016, 00:16

ok, thank you for the clarification.
sorry for my English ! i use google translat.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: Speaker function ?

#19 Post by tozett » 03 Oct 2016, 14:03

hope this doku finds it way to the wiki ... ;)

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#20 Post by psy0rz » 13 Feb 2017, 09:23

is this in the dev branch yet? or should someone make a pull request?
Please support ESPEasy development via Patreon or buy us a coffee.

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#21 Post by psy0rz » 17 Feb 2017, 00:33

I needed speaker support myself to build an Alarm system for my home. Needed the alarm to give audio feedback. (e.g. alarm enable/disable tones, window-open notification sounds etc)

I cleaned up the code (identation), and moved the functions to Misc.ino

Its avaiable in v1.1.0-beta7 in the testing plugin-set.

Edwin
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#22 Post by kniazio » 13 Mar 2017, 19:08

I have uploaded version dev6
https://github.com/letscontrolit/ESPEasy/releases
It is written in the description
Implemented speaker and tone functions from https://www.letscontrolit.com/forum/vie ... r&start=10
I get the message
Unknown or restricted command!

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#23 Post by psy0rz » 14 Mar 2017, 00:07

Its in the testing plugin set. So you need the test or dev firmware version.

I just updated the wiki: https://www.letscontrolit.com/wiki/index.php/GPIO
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#24 Post by kniazio » 14 Mar 2017, 07:00

After being exchanged plugin _P001_Switch forum
https://www.letscontrolit.com/forum/vie ... ?f=4&t=343
melodies work
It seems that in the dev version 6 is a mistake

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#25 Post by psy0rz » 14 Mar 2017, 10:34

kniazio wrote: 14 Mar 2017, 07:00 After being exchanged plugin _P001_Switch forum
https://www.letscontrolit.com/forum/vie ... ?f=4&t=343
melodies work
It seems that in the dev version 6 is a mistake
uuuhh ...what do you mean? :)
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#26 Post by kniazio » 14 Mar 2017, 11:17

psy0rz wrote: 14 Mar 2017, 10:34
kniazio wrote: 14 Mar 2017, 07:00 After being exchanged plugin _P001_Switch forum
https://www.letscontrolit.com/forum/vie ... ?f=4&t=343
melodies work
It seems that in the dev version 6 is a mistake
uuuhh ...what do you mean? :)
I mean that with version dev6 wrote melodies that have been added.
These tunes do not work
I see that RTTTL code is added to the plugin misc.ino but it did not work.
I swapped the old plugin _P001_Switch.ino and melodies work
I did it according to the description of the forum
https://www.letscontrolit.com/forum/vie ... ?f=4&t=343
post 7

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#27 Post by kniazio » 14 Mar 2017, 12:24

After sending the command:

Code: Select all

http://192.168.0.3/control?cmd=rtttl,14:d=8,o=5,b=180,c6,b,c6,p,g,g-,p,f,b,c6,p,d6,p,g,p,c6,b,c6,p,d6,p,f,g,g-,4p,g,f,4d-
I get the answer:

Code: Select all

Unknown or restricted command!
In contrast, using a modified plugin _P001_Switch.ino
After sending the command:

Code: Select all

http://192.168.0.3/control?cmd=rtttl,14:d=8,o=5,b=180,c6,b,c6,p,g,g-,p,f,b,c6,p,d6,p,g,p,c6,b,c6,p,d6,p,f,g,g-,4p,g,f,4d-
I get the answer:

Code: Select all

{
"log": "rtttl,14:d=8,o=5,b=180,c6",
"plugin": 1,
"pin": 14,
"mode": "output",
"state": 0
}

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#28 Post by psy0rz » 14 Mar 2017, 13:24

You have to use the correct binary.

If you have 4096Mb flash use: ESPEasy_v2.0.0-dev6_dev_4096.bin

If you have 1024MB flash use: ESPEasy_v2.0.0-dev6_dev_1024.bin

Notice the _dev_ at the end, that means: All the plugins that are in testing and development state.
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#29 Post by kniazio » 14 Mar 2017, 17:56

psy0rz wrote: 14 Mar 2017, 13:24 You have to use the correct binary.

If you have 4096Mb flash use: ESPEasy_v2.0.0-dev6_dev_4096.bin

If you have 1024MB flash use: ESPEasy_v2.0.0-dev6_dev_1024.bin

Notice the _dev_ at the end, that means: All the plugins that are in testing and development state.
I do not use ready .bin file alone compile
In the previous post I explained to guess exactly what's going on

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#30 Post by psy0rz » 14 Mar 2017, 18:01

ah you compiled it yourself. what did you use to compile it, Arduino IDE or platformio?

Edwin
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#31 Post by kniazio » 14 Mar 2017, 19:36

psy0rz wrote: 14 Mar 2017, 18:01 ah you compiled it yourself. what did you use to compile it, Arduino IDE or platformio?

Edwin
Arduino IDE

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#32 Post by psy0rz » 14 Mar 2017, 21:20

I still have to adjust the tutorials for that.

If you compile it now, it will not comile the TEST and DEV plugins.


if you add this to ESPEasy.ino it will work, without the other adjustments you made:

#define PLUGIN_BUILD_DEV
#define PLUGIN_BUILD_TESTING
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#33 Post by kniazio » 15 Mar 2017, 06:39

I do not understand what you mean.
I believe that in the file Misc.ino is an error, and therefore tunes do not work.
Why work with a file _P001_Switch.ino?
Attachments
_P001_Switch_z melodyjkami.rar
(3.5 KiB) Downloaded 239 times

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#34 Post by psy0rz » 15 Mar 2017, 09:37

I fixed the tutorial and source code.

Use v2.0.0-dev7 , follow this tutorial: https://www.letscontrolit.com/wiki/inde ... are_Upload

make sure you enable the testing plugin set. (in espeasy.ino)

Edwin
Please support ESPEasy development via Patreon or buy us a coffee.

kniazio
Normal user
Posts: 71
Joined: 12 Jun 2016, 11:12

Re: Speaker function ?

#35 Post by kniazio » 15 Mar 2017, 11:05

Unknown or restricted command!

psy0rz
Normal user
Posts: 232
Joined: 02 Feb 2017, 12:12

Re: Speaker function ?

#36 Post by psy0rz » 15 Mar 2017, 11:26

strange..i'm using that version and it works here.
Please support ESPEasy development via Patreon or buy us a coffee.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests