Author Topic: Questions about "Oak on the Particle Local Server"  (Read 7489 times)

malaire

  • Newbie
  • *
  • Posts: 28
Questions about "Oak on the Particle Local Server"
« on: December 07, 2016, 12:27:12 pm »
Some questions about digistump.com/wiki/oak/tutorials/localserver:

When sending default_key.pub.der to Oak, instructions mentions both base64-encoding and hex-encoding. Which one should I use?

When sending JSON to http://192.168.0.1/set as POST, what response should I get? I'm getting {"r":-1}

I'm testing this on Raspberry Pi 3 B with latest Raspbian OS. The instructions for particle-cli installation doesn't work at all.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #1 on: December 08, 2016, 09:51:18 pm »
I've updated the instructions for getting particle-cli working... it's one of those rPi specific things, as there aren't any pre-compiled binaries for the serialport module, hence it fails badly. I've tried it on two clean rPi Nov 16 Raspian images with no issues, using node.js 4.7.

Code: [Select]
sudo npm install -g particle-cli --unsafe-perm --build-from-source
I'm also having problems with the local server, and seem to be getting stuck at the same step. I'm pretty sure that "r":-1 is an error indication... IIRC it should be returning a "0" when there are no errors. I'm strongly tempted seeing if I can hack up a script kh made which has the decoding and send stuff in it as part of the process for recovering badly trashed Oaks...
« Last Edit: December 08, 2016, 09:53:53 pm by PeterF »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #2 on: December 08, 2016, 10:28:06 pm »
Ok, the "server_address_type" *may* be a typo... the code seems to indicate that it should actually be "server-address-type" (hyphens, not underscores - particle_core.cpp line 3716). The json appears to be using hypens, but the in-memory variables are using underscores.

I was able to get a "r":0 response when using POSTing {"server-address":"192.168.0.7","server-address-type":0}, but it doesn't appear to be taking...  :'(  :o

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #3 on: December 09, 2016, 03:41:05 am »
Ok, the "server_address_type" *may* be a typo... the code seems to indicate that it should actually be "server-address-type" (hyphens, not underscores - particle_core.cpp line 3716). The json appears to be using hypens, but the in-memory variables are using underscores.

I was able to get a "r":0 response when using POSTing {"server-address":"192.168.0.7","server-address-type":0}, but it doesn't appear to be taking...  :'(  :o

Did you also have 'server-public-key' there? base64 or hex -encoded?

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #4 on: December 09, 2016, 04:20:37 am »
Just found the answer, server-public-key must be hex-encoded, not base64.
Source: https://github.com/digistump/OakCore/blob/master/cores/oak/OakParticle/particle_core.cpp#L3751

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #5 on: December 09, 2016, 05:14:05 am »
I'll try this again later - currently all downloads from nodejs.org are failing so it's impossible to install NodeJS -- https://github.com/nodejs/nodejs.org/issues/1061

(This is a good reminder that relying on third parties like NodeJS or Particle is extremely stupid -- and that Oak will remain a useless device until it can be made to work with local server.)
« Last Edit: December 09, 2016, 05:39:03 am by malaire »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #6 on: December 09, 2016, 04:18:01 pm »
Just found the answer, server-public-key must be hex-encoded, not base64.

lol... that explains why I was getting ridiculously long strings for the public key / etc. I'll try that again, and see if I have any luck.

It appears nodeJS is up again btw... and they appear to have had a plan in the works to ensure exactly this issue wouldn't happen, but it wasn't operational yet...

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #7 on: December 10, 2016, 04:02:26 am »
btw, here's a small script to automate setup of server/device keys:
https://gist.github.com/malaire/92197ed20e90f3a961e55615c227fab0

Requires
Code: [Select]
sudo apt-get install curl libjson-perl
EDIT: Scripts are now in new repository: https://github.com/malaire/oak-with-rpi-server
« Last Edit: December 13, 2016, 12:21:52 am by malaire »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #8 on: December 10, 2016, 11:37:35 pm »
Very nice! Thanks for sharing! ;D

btw, regarding your comment on kickstarter which seems to be related to the script somewhat:

Quote
Local server tutorial is missing instructions for how to setup access point details. It seems that http://192.168.0.1/configure-ap is right command to use, but that doesn't seem to be documented anywhere.

The instructions are probably not there because Erik wasn't anticipating a setup like you've done... I'm actually wondering myself... I have a rPi collected via ethernet to my router, so it is doing all the DHCP serving... and I was connecting to the Oaks AP using my laptop, and then connecting to my main wifi to finish setting up the rPi... I take it your setup was different, and somehow the rPi could see the Oaks AP whilst still preserving it's normal IP? Just curious how you set that up? Subnetting? Ethernet on one, wifi on another? I'll stop there before I make too much of a fool out of my self!  :o  :-X

Edit: Then realises you're probably using a static IP on the rPi, and need to change the default IP for the Oaks AP so it goes into the same IP range as your normal wifi network. And you're logging into the rPi with a keyboard mouse rather than remotely... so don't need a second subnet... etc... duh! Maybe... possibly?  ;D

btw, there is a brief mention of configure-ap on the wiki, but you may need to look at the soft-ap doc (if the syntax hasn't been change).
« Last Edit: December 11, 2016, 12:25:32 am by PeterF »

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #9 on: December 11, 2016, 04:14:35 am »
The instructions are probably not there because Erik wasn't anticipating a setup like you've done

Currently only way to set/change wificonfig requires Particle account -- http://digistump.com/wiki/oak/tutorials/wificonfig
There really should be a way to do this also without Particle account.

... I take it your setup was different ...

I'm just switching rPi between my local WiFi and Oaks WiFi. I'm currently using Raspberry Pi 3 B as desktop computer while developing (keyboard/mouse/display connected directly, network from inbuild WiFi).

* connect to local WiFi (save ip address for next step)
* download everything needed
* install nodejs, spark-server, particle-cli
* start spark-server for a moment to generate public key, then exit

* start Oak and connect to its WiFi
* run my script to update Oak (using saved server-ip address)

now I would need to setup Oak to connect to my WiFi, switch rPi back to local WiFi and restart Oak

look at the soft-ap doc
That seems a bit insufficient. What is 'idx'? Is channel required? And getting 'pwd' correct might take a moment.

EDIT: I think I found the source of how to do this in JavaScript: https://github.com/spark/softap-setup-js/blob/master/lib/SoftAP.js
« Last Edit: December 11, 2016, 04:47:57 am by malaire »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #10 on: December 12, 2016, 02:53:51 am »
Currently only way to set/change wificonfig requires Particle account -- http://digistump.com/wiki/oak/tutorials/wificonfig
There really should be a way to do this also without Particle account.

Very true... maybe a modified version of the config page that already exists that doesn't have all the setup and particle stuff in it... since it only needs to manage the wifi config?

Nice... very nice... makes it quite a bit easier/automated than my setup.  ;D

Well, I don't know if it is newsworthy... but something I did to my Oak made it so it don't report to Particle (online) anymore... so it seems it wants to only talk to my local server.... now to get the public key stuff sorted out!  8)
« Last Edit: December 12, 2016, 02:55:37 am by PeterF »

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #11 on: December 12, 2016, 03:54:26 am »
Note that Oak doesn't really understand JSON, only a small subset (since it uses really simple parsing).

Some values must always be quoted, others must never be quoted.

Also I just noticed that 'sec' parameter for 'configure-ap' must not be last value in JSON, since Oak tries to find ',' after the value to detect where value ends:
https://github.com/digistump/OakCore/blob/d2883790322044a3f8c3a26c8812218ad486e12d/cores/oak/OakParticle/particle_core.cpp#L3814

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #12 on: December 12, 2016, 10:21:40 am »
I split the script I posted earlier into two (oak-set-server.pl and oak-get-device-key.pl) and also added new script for wifi-setup (oak-set-wifi.pl).

Those are all now in my new repository: https://github.com/malaire/oak-with-rpi-server

ps. I think I might've fried my Oak partially (I forgot that Oak is 3.3V and used 5V serial adapter). I've ordered 3.3V adapter but it takes 1-2 weeks to arrive, so unless I can get OTA updates working, I won't be doing more testing for a while.

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: Questions about "Oak on the Particle Local Server"
« Reply #13 on: December 12, 2016, 03:24:40 pm »
Also I just noticed that 'sec' parameter for 'configure-ap' must not be last value in JSON, since Oak tries to find ',' after the value to detect where value ends:
https://github.com/digistump/OakCore/blob/d2883790322044a3f8c3a26c8812218ad486e12d/cores/oak/OakParticle/particle_core.cpp#L3814

It looks like the wifi channel is specified as the last parameter, which is after sec? It looks like you pass the index number from scan-ap, the wifi SSID, the hex-encoded wifi passwd, the security type, and the wifi channel. That's what the original soft-ap syntax was anyway. This is getting interesting... so it looks like the functions on L3596 (set_config_from_JSON) and L3787 (configure_ap_from_JSON) are the two juicy ones for all this stuff.

Eek! Well, hopefully it's just the serial I/O pins that are fried if they are... I have used a 5v adapter on an Oak and it's survived ... but only once or twice as a proof-of-concept. I've also done the same frequently with the ESP-01 boards... before my 3v3 adapters turned up ;) ... so it may not be dead? I'll have to give those scripts a try (probably won't happen till tomorrow evening...) and see what happens... do they... oh nice... they display the return value if it's screwy... perfect!
« Last Edit: December 12, 2016, 03:38:41 pm by PeterF »

malaire

  • Newbie
  • *
  • Posts: 28
Re: Questions about "Oak on the Particle Local Server"
« Reply #14 on: December 13, 2016, 12:17:38 am »
It looks like the wifi channel is specified as the last parameter, which is after sec? It looks like you pass the index number from scan-ap, the wifi SSID, the hex-encoded wifi passwd, the security type, and the wifi channel. ...
I was able to get this working with just security type, SSID and pwd (not just hex-encoded, but RSA-encrypted). After configuring Oak with my current oak-set-wifi.pl script Oak is sending some messages to local server, so it can connect to wifi, but there are some other problems still present.