The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

438536 (7) [Avatar] Offline
#1
Can I enquire in section 7.4.2 Create your MQTT client application, when I execute node simple-plug.js, I encountered the script error below. Any advice? Thanks.
root@raspberrypi:/home/pi/wot-book/chapter7-implementation/part3-cloud# node simple-plug.js
module.js:427
throw err;
^

SyntaxError: /home/pi/wot-book/chapter7-implementation/part3-cloud/config.json: Unexpected token :
at Object.parse (native)
at Object.Module._extensions..json (module.js:424:27)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/pi/wot-book/chapter7-implementation/part3-cloud/simple-plug.js:3:14)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
Vlad Trifa (16) [Avatar] Offline
#2
Hello,

It's not obvious what is happening from the terminal output, could you give us a bit more information about the issue? Version of node.js you are using, what OS, etc. Are these files straight out of git or did you change anything?

Edit: it seems there's an issue with the config.json file, can you please post its contents here (obviously obfuscating your own IDs & especially API Keys)?

Thanks!
438536 (7) [Avatar] Offline
#3
Hi Vlad,

Thanks for your reply. Sorry, for not enough information before. I had repeated tried a lots of time, therefore I make a fresh start on git clone github again. Below are more info
- Hardware used: raspberry pi 3
- OS version
root@raspberrypi:/home/pi# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

-root@raspberrypi:/home/pi# node -v
v4.4.2

- I execute sh setup.sh xxx where xxx is my operator API key
- i type npm install
- Then type node simple-plug.js
- My config.json is as below
{
"operatorApiKey":"POKU0z17c7aKa89Q6ZnksBfaJiAwYAZ6tOUwWYzFXDDuMQMWec14Mh4B6zX8GKnQRirfQ7XDbiYQMZhe",
"projectId":"U3KAGMFYBDsw95wwR2ebcwtk",
"appId":"UGKdGMk2eDPw9KwRagSrSQps",
"appApiKey":"socialNetworks":,"43J6lNqKUS2Y3PfVGxePK10OxkK0bh6WUhm5D2FkLYvEpgMgK2qjYIAIXgyvTwLpkgWZuR8bkGkBctgy",
"productId":"U3KA36Fr6G8EY6waaEwSxmGs",
"thngId":"UmpUGqmRqm8EEqRRwDmH3ptn",
"thngApiKey":"ynlGvSCU0UsW4KtkGe8zqeFSqCpqzpcs7wrjAJ7AcSnbcBoxv0sht8ou2TXnuQK9ia6HGTiUD8uOAgdN"
}

I will re-generate my operator API and generate sh setup.sh xxx again after you provide some recommendation to solve the error. Appreciate your help and advice. Thanks.
Vlad Trifa (16) [Avatar] Offline
#4
Hello,

ah, the following line is not valid JSON content (cannot explain why though):

"appApiKey":"socialNetworks":,"43J6lNqKUS2Y3PfVGxePK10OxkK0bh6WUhm5D2FkLYvEpgMgK2qjYIAIXgyvTwLpkgWZuR8bkGkBctgy",

Remove the -- "socialNetworks":, -- and you should be fine with the line like this:

"appApiKey":"43J6lNqKUS2Y3PfVGxePK10OxkK0bh6WUhm5D2FkLYvEpgMgK2qjYIAIXgyvTwLpkgWZuR8bkGkBctgy",

Let us know if that works.

-v
438536 (7) [Avatar] Offline
#5
Hi Vlad,

It works. Appreciate and thanks for the help!