tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Hack Smart Lights Magpi 76

Tue Jan 01, 2019 12:16 pm

Following a successful visit to Ikea I now own the required hardware as suggested by PJ Evans.

I have carried out the setup procedure as described in Section 5, although not entirely happy that this was successful. Then for the big moment Section 6 Opening a communications channel appears to complete as it should and then I type ‘lights’ and receive the following message 'NameError: name 'lights' is not defined'.

Does anyone have the same issue? As a Python Newby I would appreciate any pointers.

Background Info:
Pi Zero W running Stretch
Lights working successfully using the Ikea remote (and indeed via Google Home)
Many thanks in anticipation

Just a thought, has anyone successfully followed the Magpi Tutorial?

robthez
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 75
Joined: Thu Oct 11, 2012 10:50 am
Location: Bournemouth

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 10:53 am

This sounds like a problem with the Python script - give it another look over to make sure it's correct, and compare it to the online version.

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 11:31 am

And if the above does not help: post *your* code and the full error message.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 3:15 pm

Thank you very much for your response. This morning I flashed my SD card with Raspbian Stretch and started from scratch. The entire output is below. Sorry, it's a bit long but it's difficult for me to know exactly what bits are relevant.

The instructions in 05 Learning to CoAP. state that I should "Enter the following, line-by-line which I have done, but it's not obvious where the line ends are. I have tried a number of different ways, but suspect the root of my problem may well have something to do with me getting this wrong.

Once again, I really appreciate your efforts, thank you.

I have attempted to attach the output in a .txt file, but cannot due to it having an invalid extension (which is of course .txt). Not my day today. Trying to add it to the body of the post results in me exceeding the 60000 characters allowed (my output is is 87346)

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 3:51 pm

First try if you can put it inside a code block.
If that doesn't work then you could post it to e.g. pastebin (https://pastebin.com/) and post a link here

Don't forget to post full error messages

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 4:02 pm

Thanks for your reply, I have read in the General Section that ZIPing will work, so attached is my text file compressed.
In the meantime, I will research how to try your other suggestions.

The file contains the complete Verbatim output so all errors are included.

Many thanks
Attachments
My Verbatim Output.zip
(10.76 KiB) Downloaded 46 times

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 4:18 pm

Hi again,

Putting in a code block still exceeded the character count, however, your other idea (new to me) seems to work so perhaps you can try:

https://pastebin.com/hCT6sD2g

Thank you.

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 4:54 pm

I had a quick look and the problem doesn't seem to be the issue with 'lights' you mentioned, but before that

Code: Select all

pi@raspberrypi:~/libcoap $ python3 -i -m pytradfri 192.169.1.217
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
Please provide the 'Security Code' on the back of your Tradfri gateway: e0nrip3jIUlaaaHI
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
DEBUG:pytradfri.api.libcoap_api:Executing 192.169.1.217 post ['15011', '9063']: {'9090': '881a06b16acf46ad92e2fcd326bde6b3'}
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/__main__.py", line 48, in <module>
    psk = api_factory.generate_psk(args.key)
  File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 164, in generate_psk
    self._psk = self.request(Gateway().generate_psk(existing_psk_id))
  File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 96, in request
    return self._execute(api_commands, timeout=timeout)
  File "/home/pi/.local/lib/python3.5/site-packages/pytradfri/api/libcoap_api.py", line 85, in _execute
    raise RequestTimeout() from None
pytradfri.error.RequestTimeout
So the error is 'pytradfri.error.RequestTimeout'. Not sure what the cause is, but web searches suggest that the security code you entered could be wrong.
Or maybe the gateway (whatever that is) needs to be restarted or reset.

tadder
Posts: 14
Joined: Sat Jan 03, 2015 4:06 pm

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 6:41 pm

Many thanks, it now works and I can't thank you enough for your assistance.
The answer does leave me with a little egg on my face, but in the spirit of sharing so no one else does the same:

Rebooted gateway - no change.

Revisited python3 -i -m pytradfri 192.168.1.XX

Thoughts !!! - hang on that IP is my pi, not the Gateway. Changed IP to match the Gateway and it now works fine.

Not my finest intellectual moment, but hey ho onwards and upwards.

Thanks again.

DirkS
Posts: 9876
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Hack Smart Lights Magpi 76

Wed Jan 02, 2019 7:47 pm

Sometimes the brain just needs a little nudge to solve a problem... :)

Return to “The MagPi”