domguinard (69) [Avatar] Offline
#1
Moving question from: https://forums.manning.com/posts/list/38254.page


Hi,
I tried pattern 3 in chapter 7, cloud gateway but the code not work. Although I have run the setup.sh file but server just hanging and not updating thng properties. I tried to build my own with local mqtt server but It cant be accessed by web browser. Could you give me some clue how to build something like evrythng? How to build a server resolving both mqtt and http request?
Thanks
domguinard (69) [Avatar] Offline
#2
Hi,

We just tested the code again and it does work for us.

Did you register with EVRYTHNG first? Did the setup.sh script populate the objects (Thngs, etc.) in your EVRYTHNG account?
Do you use Linux or Windows?

Once the script has run you need to run:
 node simple-plug.js 

to actually start the example.
431450 (10) [Avatar] Offline
#3
Hi Dom,
Really sorry for posting unrelated question in another thread.
I'm using Ubuntu 16.10. I have registered an EVRYTHNG account and got a operator API key.
Then in terminal when I run [ $ sh setup.sh XXX ], I've got an error "setup.sh: 9: setup.sh: Syntax error: "(" unexpected".
I tried again with [ $ ./setup.sh XXX ], It does steps 1-4 and also create action and redirect Url for me, and I also checked, project, product, thng has been created in my ERVYTHNG account and 5 times updated by setup.sh. But when I run
[ $ npm install ] //success
[ $ node simple-plug.js ]
The terminal just log with "Using Thng #YYY with API Key: XXX" and not updating my thng properties.
Thanks for replying soon.
domguinard (69) [Avatar] Offline
#4
Very good catch, thanks for that. I managed to reproduce your issue (on a Linux box only, not on a Mac), looking into this now. I submitted it as a bug on github if you want to track the progress:
https://github.com/webofthings/wot-book/issues/16
domguinard (69) [Avatar] Offline
#5
Okay, we managed to fix it: https://github.com/webofthings/wot-book/commit/587efd80f7a013540c7d74d30e5e6338a16396dd

Basically the issue was that on MacOS the sh is actually bash while on Ubuntu it points to dash

So when you were running the script with
sh setup.sh
on your machine it was running it with dash which does not support the same language set, hence the error.

You can now pull master:
git pull origin master
and you should get the fix. Then run
sh setup.sh XXX
again.

Essentially the fix forces using bash if it's not using it.

Thanks a lot for reporting this bug, this was a really good catch!
431450 (10) [Avatar] Offline
#6
Hi Dom,
Thanks for fix bug sh setup.sh, but the problem is still there, when I run
[ npm install ] //success
[ node simple-plug.js ]
It's not updating my thng prop. It just hangs the terminal with the line "Using Thng #XXX with API Key: YYY.
I include my output in a file.
Hoping for replying soon. ( I have trouble with this book forum when replying thread because the language display is French I guest )
domguinard (69) [Avatar] Offline
#7
Hi there,

I think what's happening is a side effect from the bug that you had with the .sh file: some resources were created but the _setStatus action is not scoped correctly (i.e., is not part of the project the app uses) as the call failed.

I fixed this in you account directly and it should now work. An alternative would have been to go to ActionTypes in the EVRYTHNG dashboard (https://dashboard.evrythng.com/resources/actiontypes) while ensuring that no project was selected (Current Project: None). Then, select the _setStatus Action and move it to the corresponding Project (Web of Things Book).

But again, I fixed that for you so it should now work, try it again.

Thanks for the report and sorry for the inconvenience.
431450 (10) [Avatar] Offline
#8
Hi Dom,
I deleted all existing projects and created a new one by [sh setup.sh XXX] command.
It all successed except {"status":404,"errors":["Custom action type _setStatus not found."]. Then I added __setStatus action type that you created in this new project, run [node simple-plug.js] and still, nothing happen. Thng can be updated by http request curl POST but cant be updated by sending mqtt request.

I think the problem is establishing connection to server because I'm running simple-plug.js file, not plug-with-control, so there nothing relate to __setStatus. I tried to connect to test.mosquito.org but it failed too. May be the connection is abandoned by my company network. I will give it a try at home.
domguinard (69) [Avatar] Offline
#9
Now, you are onto something really interesting here!

We had this types of issues with corporate firewalls while deploying projects at EVRYTHNG's customers. As a fallback the EVRYTHNG pub/sub component also supports ports 443 (secure) and 80 (unsecure) which should hopefully be open if you get access to the Web!

Try changing line 11 from simple-plug.js from:

var client = mqtt.connect("mqtts://mqtt.evrythng.com:8883", {// #B


to

var client = mqtt.connect("mqtts://mqtt.evrythng.com:443", {// #B


this should hopefully let you through. Let us know!
431450 (10) [Avatar] Offline
#10
Hi Dom,
It worked.
Thank you very much.
Now I will continue reading your book. I left it when I could not run this example.