Brewskey / spark-server

An API compatible open source server for interacting with devices speaking the spark-protocol
https://www.particle.io/
GNU Affero General Public License v3.0
54 stars 27 forks source link

Can't get a local cloud connection with photon #270

Closed ivorjawa closed 5 years ago

ivorjawa commented 6 years ago

I'm using the origin/release/v0.8.0-rc.8 branch of spark. Other versions don't work as well. I can setup the photon to the point it is rapidly blinking cyan, but I never get a local cloud connection. spark-server is the head of dev, running on a raspberry pi.

jlkalberer commented 6 years ago

@AntonPuko - can you check this out?

AntonPuko commented 6 years ago

@jlkalberer only after 3rd of aug. I don't have photon and rpi where I'm now. @ivorjawa Could you provide server logs? Usually, that behavior means that the device is trying to connect, but fails on a handshake because of wrong server/device keys

ivorjawa commented 6 years ago

I'm running on Raspberrian Jessie, the latest Brewskey spark-server, the latest particle-cli, and the latest spark firmware, origin/release/v0.8.0-rc.8 My symptoms are, no matter what combination of keys doctor, keys server, and setup I use, I never get past the rapid cyan flash. I can connect to local wifi fine, and the keys I've generated show up the spark-servers database, but the Photon will not connect to the local cloud.

I've attempted to switch the logging level to 'debug' in dist/settings.js, but I'm only seeing INFO level messages, and they're not particularly helpful.

The following log is two restarts of the server. I can see that the Photon is in some form of communication with the server, because when I kill the server the LED goes from fast blinking cyan to blinking orange. When I restart the server, it goes back to fast cyan.

The server does have the right device key:

pi@raspberrypi:~/brewski/spark-server $ cat data/db/deviceKeys.db {"deviceID":"45002a001051353532343635","algorithm":"rsa","key":"-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCl22ry3Pv8Wm+/wwuLd8ty2S0U\n2lEk9g8p+pD6twb8YTXQWj2RXuygJEd9THmInkwdwlcBIFo6W1zbfDeZ3jovW4oO\nzdg5POLhvRJFt5zfnDQs6MbBl7ZI3qY1S/JeE3R5hEFpfUyRG2/NCFL7xL+fy+vo\n0gr+lGQzXcFuoZbNlwIDAQAB\n-----END PUBLIC KEY-----\n","_id":"iIdzuP0KF9une1tc"}

pi@raspberrypi:~/brewski/spark-server $ ../nb/npm start

spark-server@0.1.1 start /home/pi/brewski/spark-server nodemon --exec babel-node ./src/main.js --watch src --watch ../spark-protocol/dist --ignore data | bunyan

[nodemon] 1.14.11 [nodemon] to restart at any time, enter rs [nodemon] watching: /home/pi/brewski/spark-server/src/*/ ../spark-protocol/dist [nodemon] starting babel-node ./src/main.js [2018-07-19T15:05:19.844Z] INFO: main.js/31125 on raspberrypi: Server IP address found (address=192.168.86.103) [2018-07-19T15:05:20.211Z] INFO: DeviceServer.js/31125 on raspberrypi: Server started (serverPort=5683) [2018-07-19T15:05:20.213Z] INFO: main.js/31125 on raspberrypi: express server started, with events (port=8080) [2018-07-19T15:05:20.388Z] INFO: PermissionManager.js/31125 on raspberrypi: Default Admin token (token=3d2d09b590b73b4f03cff9873c780b84f1e81aaf) [2018-07-19T15:05:29.673Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:05:39.682Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:05:49.685Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:05:59.695Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:09.698Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:19.708Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:29.711Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:39.721Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:49.721Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:06:59.732Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:09.733Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:19.743Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:29.748Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:39.753Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:49.762Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:07:59.770Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:08:09.773Z] INFO: DeviceServer.js/31125 on raspberrypi: Connected Devices (devices=0, sockets=0) ^C pi@raspberrypi:~/brewski/spark-server $ ../nb/npm start

spark-server@0.1.1 start /home/pi/brewski/spark-server nodemon --exec babel-node ./src/main.js --watch src --watch ../spark-protocol/dist --ignore data | bunyan

[nodemon] 1.14.11 [nodemon] to restart at any time, enter rs [nodemon] watching: /home/pi/brewski/spark-server/src/*/ ../spark-protocol/dist [nodemon] starting babel-node ./src/main.js [2018-07-19T15:08:32.422Z] INFO: main.js/31181 on raspberrypi: Server IP address found (address=192.168.86.103) [2018-07-19T15:08:32.779Z] INFO: DeviceServer.js/31181 on raspberrypi: Server started (serverPort=5683) [2018-07-19T15:08:32.782Z] INFO: main.js/31181 on raspberrypi: express server started, with events (port=8080) [2018-07-19T15:08:32.958Z] INFO: PermissionManager.js/31181 on raspberrypi: Default Admin token (token=3d2d09b590b73b4f03cff9873c780b84f1e81aaf) [2018-07-19T15:08:42.256Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:08:52.265Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:02.270Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:12.280Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:22.281Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:32.291Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:42.291Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:09:52.293Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:10:02.304Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:10:12.305Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:10:22.310Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:10:32.320Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0) [2018-07-19T15:10:42.325Z] INFO: DeviceServer.js/31181 on raspberrypi: Connected Devices (devices=0, sockets=0)

ivorjawa commented 6 years ago

The method I'm using to try to get the Photon connecting:

make clean all PLATFORM=photon program-dfu particle identify particle keys server pyoming_default_key_pub.pem --protocol tcp --host raspberrypi.lan --port 8080 cd keytemp && particle keys doctor 45002a001051353532343635 && cd .. particle setup particle list (should be online, isn't)

@AntonPuko if you send me an address, I'd be happy to send you a Photon and RPi.

Thanks!

ivorjawa commented 6 years ago

Linking reddit "thread"

https://www.reddit.com/r/particlephoton/comments/8y2uwg/has_anyone_managed_to_get_the_local_cloud_setup/

AntonPuko commented 6 years ago

@ivorjawa Nah. I'm in Russia. Postmail here is pretty shitty and there can be also problems with customs control for wifi devices. So it won't be faster than 3 aug anyways. The things you can try until that time: 1) be sure that you follow those steps for setup device: https://github.com/Brewskey/spark-server/issues/262#issuecomment-373546147 2) You can try to debug it by yourself.

  1. go to node_modules/spark-protocol/package.json and change that to https://github.com/Brewskey/spark-protocol/blob/dev/package.json#L4 "main": "./src/index.js" .
  2. the very first point where any device is connecting to the server is there: https://github.com/Brewskey/spark-protocol/blob/dev/src/server/DeviceServer.js#L208 If it never get to that, it means that you have wrong network setup either on device or on rpi.
jlkalberer commented 6 years ago

Also, did you open the COAP port? It may be blocked on the linux distro...

There was this issue in the past that may help - https://github.com/Brewskey/spark-server/issues/115

ivorjawa commented 6 years ago

It's raspbian Jesse. Pretty sure it doesn't block any ports by default but I'll double check.

Sent from my SE/30

On Jul 19, 2018, at 14:23, John Kalberer notifications@github.com wrote:

Also, did you open the COAP port? It may be blocked on the linux distro...

There was this issue in the past that may help - #115

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ivorjawa commented 6 years ago

I can connect to the coap port, and the spark-server does log the connection. So the photon isn't even getting that far along in the connection.

[kujawa@nikola spark-server]$ telnet raspberrypi.lan 5683 Trying 192.168.86.103... Connected to raspberrypi.lan. Escape character is '^]'. ?7c?|?E6??Kˏo?zX????(?p?B?8?6G??A Connection closed by foreign host.

jlkalberer commented 6 years ago

If the photon isn’t even getting that far it means you may have set the host incorrectly when configuring your photon. Can you paste the commands you used?

ivorjawa commented 6 years ago

reclaim-flash-fast: $(Q) echo "reclaim flashing (noclean) DFU " pushd $(PARTICLE_SDK)/modules && $(MAKE) all PLATFORM=photon program-dfu && popd

[kujawa@nikola photon_strip]$ particle config Current profile: pyoming Using API: http://192.168.86.103:8080 Access token: ee60a6478189626dfaab94b5e03cb65b8b50014c

1034 make reclaim-flash-fast 1035 particle identify 1036 particle setup 1037 particle keys server pyoming-default_key.pub.der --protocol tcp --host 192.168.86.103 --port 8080 1038 cd keytemp && particle keys doctor 45002a001051353532343635 && cd ..

ivorjawa commented 6 years ago

This might be part of the problem.
How do I create a valid token?

(opencv_env)[kujawa@nikola photon_strip]$ particle token list Checking with the cloud... ? Using account admin Please enter your password: [hidden]

Token: undefined Expires at: undefined

Token: undefined Expires at: undefined

Token: undefined Expires at: undefined

Token: undefined Expires at: undefined

(opencv_env)[kujawa@nikola photon_strip]$

ivorjawa commented 6 years ago

(opencv_env)[kujawa@nikola photon_strip]$ particle token list Checking with the cloud... ? Using account pyoming@isbroken.com Please enter your password: [hidden]

Token: undefined Expires at: undefined

(opencv_env)[kujawa@nikola photon_strip]$ particle token create ? Using account pyoming@isbroken.com Please enter your password: [hidden] Error while creating a new access token: Invalid client: client is invalid

AntonPuko commented 6 years ago

@ivorjawa Just reached my photon and RPI and tested. It's working as expected. Your problem could be in this command particle keys server pyoming-default_key.pub.der --protocol tcp --host 192.168.86.103 --port 8080 you don't need to provide the port when uploading server keys to the device. Notice, actually spark-server consists of two servers running at one time on different ports: 1) express server running on port 8080 that serves REST api 2) sockets server running on port 5683 to which devices connect to.

As I said, durring the setup you should follow those instructions very carefully https://github.com/Brewskey/spark-server/issues/262#issuecomment-373546147

jlkalberer commented 5 years ago

@ivorjawa - did this solve your problem?

ivorjawa commented 5 years ago

Oh for fuck's actual sake. hangs head Thanks. That works. Fffffffffffffffffff