GRiSP.io Client Library for GRiSP. This library enables secure communication between your GRiSP2 board and the GRiSP.io services using Mutual TLS (mTLS). To get started, add this application as a dependency in your GRiSP2 project.
grisp_updater_grisp2
,
make sure to add grisp_updater_grisp2
as a dependency in your project as well.
- grisp_connect
The configure
method of the rebar3_grisp
version >= 2.6.0 will add grisp_connect
with the needed configurations to your GRiSP application. See GRiSP Wiki/Use-your-GRiSP-2-board-with-GRiSP.io.
Add
{dep, [{grisp_connect, "1.0.0"}]}
to your rebar.config
file.
If you still need to link your device configure the device linking token in your sys.config
:
[ {grisp_connect, [
{device_linking_token, <<"...">>}
]}].
You can find your device linking token on GRiSP.io/grisp_manager under "How to Link a Device/Option 2: Manual Linking (Ethernet / Wifi)".
You can also skip this configuration and insert the token manually later.
> grisp_connect:is_connected().
true
> grisp_connect:ping().
{ok,<<"pong">>}
> grisp_connect:link_device(<<"...">>).
Or, if your token is configured in the environment:
> grisp_connect:link_device().
grisp_connect:link_device
may fail with the following errors.
Common Errors:
token_expired
: regenerate one from the web pageinvalid_token
: please double check you typed it correctlytoken_undefined
: you calledgrisp_connect:link_device/0
without settingdevice_linking_token
disconnected
: check that your board can connectdevice_already_linked
: please do not steal GRiSP boards 😏 if you need to unlink a GRiSP board see below...
We currently do not expose a public API to unlink a Device. Please reach out to us for assistance.
If you encounter any problems or have questions, don't hesitate to contact support. Happy coding!
This option is set to true
as default. Set it to false
to prevent automatic connection to GRiSP.io on boot.
In such case the state machine that maintains the connection can be started manually using grisp_connect_client:connect()
.
An optional NTP client can be started using option {ntp, true}
.
Such client is disabled by default ({ntp, false}
), and is not required to authenticate with GRiSP.io. The client sets the time using grisp_rtems:clock_set/1
Accepts an integer that represents time in milliseconds, default value is 5_000
.
Allows to tweak the timeout of each API request going through the websocket.
Accepts an integer that represents time in milliseconds, default value is 60_000
.
Allows to tweak the timeout between expected ping frames from the server.
If the timeout is exceeded, the socket is closed and a new connection is attempted.
Accepts an integer that represents time in milliseconds, default value is 2_000
.
Sets the intervall between each log batch dispatch to grisp.io.
Accepts an integer that represents the maximum number of logs that can be batched together, default value is 100
.
TLS settings are managed through the grisp_cryptoauth TLS options.
grisp_connect sets the following options as default values if no tls_server_trusted_certs_cb
is setup. Refer to the grisp_cryptoauth
README in case you want to overrride the default certifi
CAs.
% Example sys.config
[
...
{grisp_cryptoauth, [
{tls_server_trusted_certs_cb, {certifi, cacerts, []}}
]}
]
Once this app is started, it forwards all logs to GRiSP.io without the need of setting up anything. The only logs that we do not catch are the ones generated before grisp_connect
boots.
If you want to see ALL logs, even from applications that boot before grisp_connect
, you need to disable the default logger handler and set the grisp_connect handler as the default one. This involves changing the kernel
and grisp_connect
app configuration settings in your sys.config file.
You can copy paste these settings. Here we both swap the default logger handler with the grisp_connect logger handler and also request it to print logs to stdout.
% sys.config
[
{kernel, [
% Disable 'default' handler (which buffers all log events in logger).
{logger, [{handler, default, undefined}]}
]},
{grisp_connect,[
{logger, [
% Enable the grisp_connect handler as default,
% so that it will receive all events from boot
{handler,
default, % name
grisp_connect_logger_bin, % module
#{
formatter => {grisp_connect_logger_bin, #{
% To see logs printed on the USB serial appoint a logger
% formatter module of your choice and set the stdout
% configuration stdout => {Formatter, FormatterConfig}
stdout => {logger_formatter, #{}}
}}
}
}
]}
]}
].
Add an entry in your local hosts file so the domain www.seawater.local points to your local development server.
Start a local development shell:
rebar3 as local shell
Run tests:
rebar3 ct
Add an entry in the grisp hosts file so the domain www.seawater.local points to your local development server.
e.g. using ifconfig
command (MacOS and older linux):
echo "$(ifconfig | grep 'inet ' | grep -v 127.0.0.1 | awk '{ print $2 }' | head -n 1) www.seawater.local" >> grisp/default/common/deploy/files/etc/hosts
]
e.g. using ip
command (Newer linux):
echo "$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d/ -f1 | head -n 1) www.seawater.local" >> grisp/default/common/deploy/files/etc/hosts
To deploy the release, configure rebar3_grisp's deploy configuration in rebar.config and then run:
rebar3 as dev grisp deploy
To deploy on GRiSP hardware for production, configure rebar3_grisp's deploy configuration in rebar.config and then run:
rebar3 as prod grisp deploy