How to use the publish subscribe - awootton/knotfreeiot GitHub Wiki

How to access the unix time server via the web.

Simply visit http://get-unix-time.knotfree.io/get/time and the return will be the unix time in seconds.

get-unix-time is an address that is being watched by a simple piece of code. There are more examples written for Arduino over at mqtt5nano. Note that the command get time is written as /get/time for the web version. Visit http://get-unix-time.knotfree.io/help to see the other commands served by get-unix-time.

How to connect using text mode and netcat.

We will create a tcp connection to the text based service at port 7465 using netcat. No drivers required.

In a terminal window enter:

nc knotfree.io 7465

Then, we will send a connect command with an access token.

C token "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTc2MTQ5MjMsImlzcyI6Il85c2giLCJqdGkiOiJJc2dLamd1RmdfVjNzaVVIYWQ3MFNyVlMiLCJpbiI6MTAyNCwib3V0IjoxMDI0LCJzdSI6MjAsImNvIjoyMCwidXJsIjoia25vdGZyZWUubmV0In0.9N6kW6QK4ZUk9129uzJDnU1jSrX6XTcHthsQZiAFL7nwfzRNNEqOWeZgjKlL7ekcHMF-H0VTHKizXZoR1J1_BA"

If the token here is stale or overloaded and you need your own you can get that from http://knotfree.net/. Then we will make up a random, and hopefully unique, address for ourselves for this session. We will 'subscribe' to it.

S myaddresstopicchannelthing82754459

Then we can send the command "get time" to the address "get-unix-time". Note that we send our address as the return address.

P get-unix-time myaddresstopicchannelthing82754459 "get time"

The reply is a P (for publish) in an array of strings and the destination address and the source address have been changed into a hashed format. It looks like this:

[P,=AAFKYuRRQIKzSiS2MzHbg65zVm05snxI,=xOZPbNiNsA_lM_6xJEwM1C7YmVMGlDpA,1666078249]

Where 1666078249 is the current unix time in seconds. The address get-unix-time will respond to several commands. Sent it a help command to see the possibilities.

We can do all of this at the same time by pasting this into a terminal:

nc knotfree.io 7465
C token "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTc2MTQ5MjMsImlzcyI6Il85c2giLCJqdGkiOiJJc2dLamd1RmdfVjNzaVVIYWQ3MFNyVlMiLCJpbiI6MTAyNCwib3V0IjoxMDI0LCJzdSI6MjAsImNvIjoyMCwidXJsIjoia25vdGZyZWUubmV0In0.9N6kW6QK4ZUk9129uzJDnU1jSrX6XTcHthsQZiAFL7nwfzRNNEqOWeZgjKlL7ekcHMF-H0VTHKizXZoR1J1_BA"
S myaddresstopicchannelthing82754459
P get-unix-time myaddresstopicchannelthing82754459 "help"

One may also subscribe to the 'testtopic' and get periodic messages. Note that this is not our proper request/response format.

nc knotfree.io 7465
C token "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2OTc2MTQ5MjMsImlzcyI6Il85c2giLCJqdGkiOiJJc2dLamd1RmdfVjNzaVVIYWQ3MFNyVlMiLCJpbiI6MTAyNCwib3V0IjoxMDI0LCJzdSI6MjAsImNvIjoyMCwidXJsIjoia25vdGZyZWUubmV0In0.9N6kW6QK4ZUk9129uzJDnU1jSrX6XTcHthsQZiAFL7nwfzRNNEqOWeZgjKlL7ekcHMF-H0VTHKizXZoR1J1_BA"
S testtopic

and then wait for tens of seconds.