tableflip / nodebot-workshop

A nodeschool workshop on how to get your ardunio alive with johnny-five
https://www.npmjs.org/package/nodebot-workshop
210 stars 59 forks source link

Ping Bell: Piezo didn't play a tone when sent a UDP message — unsure of solution? #41

Closed IainIsCreative closed 5 months ago

IainIsCreative commented 7 years ago

Hello hello,

Just got on board with nodebot-workshop, really enjoying it and finding everything a breeze to understand, it's very well done. However, on exercise 6, I get the following error:

Piezo didn't play a tone when sent a UDP message 

Now, I've compared my code to the solution, even trying a copy+paste at one point, yet it still fails. Is there something I'm missing here? Is something outdated?

Click to see code below. ```javascript var five = require('johnny-five'); var dgram = require('dgram'); var board = new five.Board(); board.on('ready', function() { var piezo = new five.Piezo(8); var server = dgram.createSocket('udp4'); server.on('message', function() { piezo.tone(five.Piezo.Notes.c4, 1000); }); server.bind(1337); }); ```

Answers on a postcard.

alanshaw commented 7 years ago

Probably something outdated...thanks for reporting

olizilla commented 7 years ago

Aye, this is an issue that popped up for someone during the last nodebots meetup, but we ran out of time debugging it. @IainIsCreative your solution looks legit. Do you have any time to chase this gremlin down?

IainIsCreative commented 7 years ago

@olizilla thanks for getting back! Unfortunately, I do not. I'm currently working on other projects and I'm not 100% sure how to debug this right now. Sorry! 😭😭

aherreraGH commented 7 years ago

Hello everyone,

I'm having the same issue. My original code even included "on error" and "on listening" to see if maybe it was something else. No errors reported, and listening was spitting out to the console "listening to port 1337". Then I changed it to the given solution on here, and still unable to get exercise #6 to pass. :(

Anyone been able to update the workshop? I'm loving these mini workshops, hopefully someday I'll be able to create one to help others learn some new techie.

Thanks in advance.

aherreraGH commented 7 years ago

I added a console.log(piezo); to my message block, and saw that there was no "tone" reference anywhere.

The test case is checking to see if the callCount has increased.

test.truthy(piezo.tone.callCount > initial.tone.callCount, 'speaker_played_tune_on_udp_message')

I'm guessing this doesn't pass because the tone and tone.callCount do not exist in the piezo object.

When I use piezo.play(...), I can see:

     called: true,
     notCalled: false,
     calledOnce: true,
     calledTwice: false,
     calledThrice: false,
     callCount: 1,

That changes from 0 to 1.

Just a quick observation. I could be wrong on the root cause.

NoRoboto commented 7 years ago

@aherreraGH You are right, piezo.tone currently does not exist, simply changing the lines containing tone by play will solve the problem. (nodebot-workshop/exercises/ping_bell/exercise.js):


tone: {callCount: piezo.tone.callCount}
to
play: {callCount: piezo.play.callCount}

test.truthy(piezo.tone.callCount > initial.tone.callCount, 'speaker_played_tune_on_udp_message')
to
test.truthy(piezo.play.callCount > initial.play.callCount, 'speaker_played_tune_on_udp_message')

I have opened a pull request #45 that solves this error, feel free to check it.

gorhgorh commented 7 years ago

it is not as simple as it sounds, since this fix require to update j5 for the workshopper as well (so it can run the tests with the new method) so it may raise other problems, I'll have a go at updating J5 for the workshopper and check the exercises this weekend if nobody started this yet

markpete commented 6 years ago

I've submitted pull request #47 that includes the @NoRoboto fix and updated j5 dependencies. I'd appreciate it if someone could take a look and approve.

olizilla commented 5 months ago

Mark's fixes got published back in v3.2.1. 🚀