Category Archives: Uncategorized

Adding Openbsd to stats repository

Here we are !!

We are in the battle of powerpc arch, thanks to OpenBSD I have working some MacMini and other old powerpc arch!!

You can download this –> https://pkgstat-openbsd.perso.pw/?utm_source=discoverbsd


```
bash-4.4$ cat send_stats.sh
#!/bin/sh

# https://pkgstat-openbsd.perso.pw/receive.php
STATHOST=pkgstat-openbsd.perso.pw
STATPATH=/receive.php

OS=$(uname -s)
if [ ! "$OS" = "OpenBSD" ]
then
printf "$OS isn't supported\n"
exit 2
fi

MACHINE_ID=$((mount -v | sed -ne 's,.* (\(.*\)) on / .*,\1,p'; \
sysctl hw.uuid; hostname) | sha256)
ARCH=$(uname -p)
VERSION=$(sysctl -n kern.version | awk '/^OpenBSD/ { print $2 }')

# Package list with categories and flavors
PKG_LIST=$(pkg_info -q -P)

DATA="uuid=$MACHINE_ID&arch=$ARCH&osversion=$VERSION&pkglist=$PKG_LIST"
# SENDING DATAAAAAAAA !
printf '%s\r\n' \
"POST $STATPATH HTTP/1.1" \
"Host: $STATHOST" \
'User-Agent: sendstats' \
'Accept: */*' \
"Content-length: ${#DATA}" \
'Content-Type: application/x-www-form-urlencoded' \
'' \
"$DATA" \
| nc -w 1 -c "$STATHOST" 443

# Did it work ?
if [ $? -ne 0 ]
then
printf 'Could not send data\n'
exit 3
fi
```

And then you can run it !


bash-4.4$ ./send_stats.sh
sysctl: hw.uuid: value is not available
HTTP/1.1 200 OK
Connection: keep-alive
Content-type: text/html; charset=UTF-8
Date: Sat, 26 Jan 2019 15:55:18 GMT
Server: OpenBSD httpd
Transfer-Encoding: chunked
X-Powered-By: PHP/7.0.32

21
Hello ! You are new ! Welcome :)

0

bash-4.4$

Just wait to see my packaged added there !

Analyzing Kura Logs in CloudService MQTT

This note is about how to understand basic action in kura logs so I asume you have installed kura and mqtt working in your IoT stuff.

BeaconScanner Item

The beaconScanner is a openSource project and you can use the default code or tune your code , in this example we use the default.

The beaconScanner use the bluetooth device so we have this process running maybe it depends hardware.

 

root@rg-10-20-s0:~# ps auxww|grep -i hcidump |grep -v grep
root 12136 0.0 0.0 2132 432 ? S 22:25 0:00 hcidump -i hci0 -R -w /dev/fd/3
root@rg-10-20-s0:~#

Then you can start your BeaconScanner

018-06-10 22:35:23,923 [qtp3671452-143] WARN o.e.k.n.a.v.l.WpaSupplicantConfigReader - WPA in client mode is not configured
2018-06-10 22:35:23,930 [qtp3671452-143] WARN o.e.k.n.a.v.l.PppConfigReader - getModemConfig() :: PPPD peer file does not exist - /etc/ppp/peers/HE910-D_2-1.5
2018-06-10 22:35:24,144 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Loading init configurations from: 1528669870428...
2018-06-10 22:35:24,552 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Merging configuration for pid: org.eclipse.kura.example.beacon.scanner.BeaconScannerExample
2018-06-10 22:35:24,561 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Updating Configuration of ConfigurableComponent org.eclipse.kura.example.beacon.scanner.BeaconScannerExample ... Done.
2018-06-10 22:35:24,597 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Starting bluetooth le beacon scan...
2018-06-10 22:35:24,788 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Writing snapshot - Saving /opt/eurotech/esf/data/snapshots/snapshot_1528670124562.xml...
2018-06-10 22:35:25,372 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Writing snapshot - Saving /opt/eurotech/esf/data/snapshots/snapshot_1528670124562.xml... Done.
2018-06-10 22:35:25,375 [qtp3671452-143] INFO o.e.k.c.c.ConfigurationServiceImpl - Snapshots Garbage Collector. Deleting /opt/eurotech/esf/data/snapshots/snapshot_1528665378674.xml
2018-06-10 22:35:25,839 [qtp3671452-147] WARN o.e.k.n.a.v.l.WpaSupplicantConfigReader - WPA in client mode is not configured
2018-06-10 22:35:25,845 [qtp3671452-147] WARN o.e.k.n.a.v.l.PppConfigReader - getModemConfig() :: PPPD peer file does not exist - /etc/ppp/peers/HE910-D_2-1.5
2018-06-10 22:35:26,062 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 22:35:26,068 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 22:35:26,081 [DataServiceImpl:Submit] INFO o.e.k.c.d.DataServiceImpl - DataPublisherService not connecte
d

The bold text show you the most important stuff, where the messages is stored, two first bold messages, then try to connect to cloud service (mqtt broker)
The third bold messages is about cloud service, from now is off.

#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 This is the TOPIC, the two first level are set in the kura dashboard the other one are set in the beaconScanner code.

Then after start beaconScanner two new process appear in order to use bluetooth command.
root 13218 0.0 0.0 1588 160 ? S 22:35 0:00 hcitool -i hci0 lescan-passive --duplicates
root 13220 0.0 0.2 2896 1184 ? S 22:35 0:00 /bin/bash /tmp/BluetoothUtil.btsnoopdump.sh hci0
root 13222 0.0 0.0 2132 432 ? S 22:35 0:00 hcidump -i hci0 -R -w /dev/fd/3

If we stop the beaconScanner now, those process must be killed.

2018-06-10 22:48:41,896 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Killing hcitool...
2018-06-10 22:48:41,956 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Killing btdump...
2018-06-10 22:48:41,956 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.u.BluetoothProcess - Closing streams and killing...

Then just only appear…

root 13222 0.0 0.0 2132 432 ? S 22:35 0:00 hcidump -i hci0 -R -w /dev/fd/3

So if you start the beaconScanner then you remove battery the logs show do not show you anymore this Beacon or if you move this beacon so far away from the scanner.

CLOUDSERVICE
This is thew way where you connect to a broker, using different protocols or services, in this case I m using the same broker created in previous post.
Let start to connect our cloud service from your kura dashboard and then checks logs.(remember we have beaconscanner running but no one beacon are on or near my scanner).

2018-06-10 22:54:20,096 [qtp3671452-42] INFO o.e.k.c.d.DataServiceImpl - Reconnect task running. Stopping it
2018-06-10 22:54:20,097 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - Creating a new client instance
2018-06-10 22:54:20,098 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - Using memory persistence for in-flight messages
2018-06-10 22:54:20,099 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # ------------------------------------------------------------
2018-06-10 22:54:20,100 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # Connection Properties
2018-06-10 22:54:20,101 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # broker = ws://www.itrestauracion.com.ar:9001
2018-06-10 22:54:20,102 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # clientId = baticueva
2018-06-10 22:54:20,103 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # username = batman
2018-06-10 22:54:20,103 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # password = XXXXXXXXXXXXXX
2018-06-10 22:54:20,104 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # keepAlive = 30
2018-06-10 22:54:20,105 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # timeout = 20
2018-06-10 22:54:20,105 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # cleanSession = true
2018-06-10 22:54:20,106 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # MQTT version = 3.1.1
2018-06-10 22:54:20,106 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # willDestination = dc/batman/baticueva
2018-06-10 22:54:20,107 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # willMessage =
2018-06-10 22:54:20,108 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - #
2018-06-10 22:54:20,109 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # Connecting...
2018-06-10 22:54:21,206 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # Connected!
2018-06-10 22:54:21,206 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - # ------------------------------------------------------------
2018-06-10 22:54:21,207 [qtp3671452-42] INFO o.e.k.c.d.DataServiceImpl - Notified connected
2018-06-10 22:54:21,207 [qtp3671452-42] INFO o.e.k.c.d.DataServiceImpl - New session established. Unpublishing all in-flight messages. Disregarding the QoS level, this may cause duplicate messages.
2018-06-10 22:54:21,217 [qtp3671452-42] INFO o.e.k.c.d.t.m.MqttDataTransport - Subscribing to topic: dc/dc/batman/baticueva/# with QoS: 1
2018-06-10 22:54:21,609 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,610 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,611 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,612 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,612 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,613 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,614 [qtp3671452-42] INFO o.e.k.c.p.ProvisioningServiceImpl - onConnectionEstablished
2018-06-10 22:54:21,614 [qtp3671452-42] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 22:54:21,615 [qtp3671452-42] INFO c.e.f.d.i.DiagnosticsServiceImpl - Connection established
2018-06-10 22:54:21,615 [qtp3671452-42] INFO c.e.f.d.i.DiagnosticsServiceImpl - Connection established

Here we have in the top the main data of where are you doing your connection, so you can see a lot of stuff where you set before in your dashboard.
o.e.k.c.d.t.m.MqttDataTransport – Subscribing to topic: dc/dc/batman/baticueva/# with QoS: 1 With this we are acting as subscriber so the mqtt broker are ready to receive any data scanned by our beaconScanner app. And then a lot of services to check connections.

How many messages you see in publishing depends in how you did your configuration in cloud service for kura services and a lot of values like, QoS,etc,etc.Now lets start to put battery to our beacon device.

2018-06-10 23:04:14,568 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:04:14,574 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:04:14,577 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:04:26,382 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:04:26,385 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:04:26,388 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0

1528671854: Received PUBLISH from baticueva (d0, q0, r0, m0, ‘dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6’, … (129 bytes))
1528671866: Received PUBLISH from baticueva (d0, q0, r0, m0, ‘dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6’, … (128 bytes))

Yo can see now that our beaconScanner detect and publish your messages.

Here we established a connection wit mqttlen client form MacOSX

Those logs are from mqtt docker logs, you can check how mqtt broker send and receive data.
1528671933: New client connected from 45.232.92.159 as maquina (c1, k120, u'batman').
1528671933: Sending CONNACK to maquina (0, 0)
1528671947: Received SUBSCRIBE from maquina
1528671947: dc/batman/baticueva/# (QoS 0)
1528671947: maquina 0 dc/batman/baticueva/#
1528671947: Sending SUBACK to maquina

Now you can check we have the client maquina that is my machine that works as subscriber getting al messages that my IOT device send to my mqtt broker.
So we have two subscriber, my broker and my client.
The beacon scanner detect the beacon and send it to my IOT that subscribe all incoming beacon detection and my client maquina connect to the broker only to specific topic, so it is the reason why we have received and sending in each cases.

1528671956: Received PINGREQ from baticueva
1528671956: Sending PINGRESP to baticueva
1528671970: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))
1528671970: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))

We detect the second beacon, store wit topic and store message and then send topic to brocker, The process housekeeper delete all confirmed messages.

2018-06-10 23:06:10,629 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:06:10,632 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:06:10,635 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:09:04,357 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask started.
2018-06-10 23:09:04,357 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask: Delete confirmed messages...
2018-06-10 23:09:04,441 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask ended.

Now we can put the battery again and just wait a while in order to publish hundred of messages….
After that test, try to remove battery or go far away with your beacon and the logs will stop, then go back with beacon and stop cloud service in order to scan beacon and store it.

2018-06-10 23:24:42,546 [qtp3671452-147] WARN o.e.k.n.a.v.l.WpaSupplicantConfigReader - WPA in client mode is not configured
2018-06-10 23:24:42,551 [qtp3671452-147] WARN o.e.k.n.a.v.l.PppConfigReader - getModemConfig() :: PPPD peer file does not exist - /etc/ppp/peers/HE910-D_2-1.5
2018-06-10 23:24:42,770 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Loading init configurations from: 1528671660393...
2018-06-10 23:24:43,181 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Merging configuration for pid: org.eclipse.kura.data.DataService
2018-06-10 23:24:43,192 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Updating Configuration of ConfigurableComponent org.eclipse.kura.data.DataService ... Done.
2018-06-10 23:24:43,210 [Component Resolve Thread (Bundle 6)] INFO o.e.k.c.d.DataServiceImpl - Updating org.eclipse.kura.data.DataService...
2018-06-10 23:24:43,211 [Component Resolve Thread (Bundle 6)] INFO o.e.k.c.d.DataServiceImpl - Get Throttle with burst length 3 and send a message every 3000 millis
2018-06-10 23:24:43,448 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Writing snapshot - Saving /opt/eurotech/esf/data/snapshots/snapshot_1528673083193.xml...
2018-06-10 23:24:43,770 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Writing snapshot - Saving /opt/eurotech/esf/data/snapshots/snapshot_1528673083193.xml... Done.
2018-06-10 23:24:43,773 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Snapshots Garbage Collector. Deleting /opt/eurotech/esf/data/snapshots/snapshot_1528669530806.xml
2018-06-10 23:24:44,216 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask started.
2018-06-10 23:24:44,216 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask: Delete confirmed messages...
2018-06-10 23:24:44,219 [HouseKeeperTask] INFO o.e.k.c.d.s.HouseKeeperTask - HouseKeeperTask ended.
2018-06-10 23:24:51,165 [qtp3671452-146] INFO o.e.k.c.d.t.m.MqttDataTransport - Disconnecting...
2018-06-10 23:24:51,166 [qtp3671452-146] INFO o.e.k.c.d.DataServiceImpl - Notified disconnecting

Stopped CloudService and deactivate te auto start.

we can see now a lot of messages like this.

2018-06-10 23:25:15,886 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:15,889 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:15,890 [DataServiceImpl:Submit] INFO o.e.k.c.d.DataServiceImpl - DataPublisherService not connected
2018-06-10 23:25:26,711 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:26,714 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:26,715 [DataServiceImpl:Submit] INFO o.e.k.c.d.DataServiceImpl - DataPublisherService not connected
2018-06-10 23:25:37,533 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:37,536 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:25:37,536 [DataServiceImpl:Submit] INFO o.e.k.c.d.DataServiceImpl - DataPublisherService not connected

It is because the beacon is there but the cloud service is inactive.Lets wait to store a some of then and stop beacon scanner.

2018-06-10 23:28:04,818 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Killing hcitool...
2018-06-10 23:28:04,884 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Killing btdump...
2018-06-10 23:28:04,884 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.u.BluetoothProcess - Closing streams and killing...

Now lets go to connect cloud service again.

So old stored messages are there
2018-06-10 23:28:49,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:28:52,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:28:55,973 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:28:58,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:01,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:04,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:07,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:10,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:13,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:16,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:19,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:29:22,972 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:

and we can check that are recived by broker.
1528673328: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673328: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673329: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673329: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673329: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673329: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673330: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673330: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673333: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))
1528673333: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))
1528673336: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (128 bytes))
1528673336: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (128 bytes))
1528673339: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))
1528673339: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (129 bytes))
1528673342: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673342: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673345: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673345: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673348: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673348: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673351: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673351: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673354: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673354: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673357: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673357: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673360: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673360: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673363: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673363: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673366: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673366: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673369: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673369: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673374: Received PINGREQ from maquina

And then after a while they stop , because no more messages are in the queue .

And when we start again beaconscanner start again to detect and publish.
2018-06-10 23:31:17,121 [Component Resolve Thread (Bundle 6)] INFO o.e.k.l.b.l.BluetoothLeScanner - Starting bluetooth le beacon scan...
2018-06-10 23:31:17,315 [qtp3671452-147] INFO o.e.k.c.c.ConfigurationServiceImpl - Writing snapshot - Saving /opt/eurotech/esf/data/snapshots/snapshot_1528673477084.xml...
2018-06-10 23:31:17,575 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:31:17,581 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:31:17,583 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0

Now, the messages are there in broker.

1528673477: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673477: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673490: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673490: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673494: Received PINGREQ from maquina

Disconnect the cloud service from broker, lets try to store messages and check what happen after change the option in kura dashboard where show you
1528673949: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673949: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673960: Received PUBLISH from baticueva (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673960: Sending PUBLISH to maquina (d0, q0, r0, m0, 'dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6', ... (130 bytes))
1528673964: Received DISCONNECT from baticueva
1528673965: Client baticueva disconnected.

Messages still apearing and sending all of them…

2018-06-10 23:44:46,860 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.t.m.MqttDataTransport - # Connected!
2018-06-10 23:44:46,860 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.t.m.MqttDataTransport - # ------------------------------------------------------------
2018-06-10 23:44:46,860 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.DataServiceImpl - Notified connected
2018-06-10 23:44:46,861 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.DataServiceImpl - New session established. Dropping all in-flight messages.
2018-06-10 23:44:46,863 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.t.m.MqttDataTransport - Subscribing to topic: dc/dc/batman/baticueva/# with QoS: 1
2018-06-10 23:44:47,240 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,241 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,241 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,242 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,242 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,243 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,243 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.p.ProvisioningServiceImpl - onConnectionEstablished
2018-06-10 23:44:47,244 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.Cloudlet - Cloud Client Connection Restored
2018-06-10 23:44:47,244 [DataServiceImpl:ReconnectTask] INFO c.e.f.d.i.DiagnosticsServiceImpl - Connection established
2018-06-10 23:44:47,245 [DataServiceImpl:ReconnectTask] INFO c.e.f.d.i.DiagnosticsServiceImpl - Connection established
2018-06-10 23:44:47,255 [DataServiceImpl:ReconnectTask] INFO o.e.k.c.d.DataServiceImpl - Connected. Reconnect task will be terminated.
2018-06-10 23:44:47,264 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:47,286 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:47,290 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:47,613 [qtp3671452-143] WARN o.e.k.n.a.v.l.WpaSupplicantConfigReader - WPA in client mode is not configured
2018-06-10 23:44:47,619 [qtp3671452-143] WARN o.e.k.n.a.v.l.PppConfigReader - getModemConfig() :: PPPD peer file does not exist - /etc/ppp/peers/HE910-D_2-1.5
2018-06-10 23:44:48,238 [qtp3671452-110] WARN o.e.k.n.a.v.l.WpaSupplicantConfigReader - WPA in client mode is not configured
2018-06-10 23:44:48,244 [qtp3671452-110] WARN o.e.k.n.a.v.l.PppConfigReader - getModemConfig() :: PPPD peer file does not exist - /etc/ppp/peers/HE910-D_2-1.5
2018-06-10 23:44:48,448 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:44:48,463 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:44:48,602 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:51,603 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:54,602 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:57,602 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:44:59,267 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Storing message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:44:59,279 [BluetoothProcess BTSnoop Gobbler] INFO o.e.k.c.d.DataServiceImpl - Stored message on topic :#account-name/#client-id/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6, priority: 5
2018-06-10 23:45:00,602 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0
2018-06-10 23:45:03,603 [DataServiceImpl:Submit] INFO o.e.k.c.d.t.m.MqttDataTransport - Publishing message on topic: dc/batman/baticueva/BeaconScannerExample/beacons/AC:23:3F:24:9A:C6 with QoS: 0

So, let try to read and read and test to understand why this is happening …

Run Basic Mosquitto Broker in Docker

Steps to run a mosquitto broker in a docker:

1- Create two files:

First one mosquitto.conf where you have the basic configuration for your broker. We explain the mosquitto passwd file later.

[dalmine@rosas mosquitto]$ cat mosquitto.conf
listener 9001
protocol websockets
allow_anonymous false
password_file /mosquitto/config/passwd
[dalmine@rosas mosquitto]$

Then create an empty passwd file.

[dalmine@rosas mosquitto]$touch passwd

 

The first line of mosquitto.conf is about listener, 9001 is the default for websocket, I choose it because you can build or code other client with a lot of languages using webscoket, also you have mqtt 1883, mitts 8883 or random port as you wish , but you need to choose the protocol.

2- Set password to login

/ # mosquitto_passwd passwd alliot
Error: Empty password.
Password: / #

/ # cat passwd
batman:$6$3qbtsdsdfsdfsdfsfdsdfshdflsjdfjlksdfhskdjfh==
/ # ls

We have the command mosquitto_passwd it is part of mosquitto packages.

 

3- Run Docker

Then we need to run docker command with a lot parameter we want to avoid configuration with any provisioning tools like compose,k8s,etc,etc,etc…

 

[dalmine@rosas mosquitto]$ sudo docker run -it -p 9001:9001 -v $(pwd)/mosquitto.conf:/mosquitto/config/mosquitto.conf -v $(pwd)/passwd:/mosquitto/config/passwd -d –name mosquitto eclipse-mosquitto
91652c904c86220f43ad6d7de2402f54c30f438bd3f59b217ef6fb7e4c61127e

The command is (ONE LINE) –> docker run -it -p 9001:9001 -v $(pwd)/mosquitto.conf:/mosquitto/config/mosquitto.conf -v $(pwd)/passwd:/mosquitto/config/passwd -d –name mosquitto eclipse-mosquitto

 

4-Check logs:

[dalmine@rosas mosquitto]$ docker logs -f mosquitto
1528666018: mosquitto version 1.4.12 (build date 2017-06-01 13:03:46+0000) starting
1528666018: Config loaded from /mosquitto/config/mosquitto.conf.
1528666018: Opening websockets listen socket on port 9001.

 

We are open to receive new connections. Now we can use the mosquitto client command  line or any web/app client.

1528667142: New client connected from 45.232.92.159 as lens_HJ9OowTbqNS11toqxXxt4eFnFew (c1, k120, u’alliot’).1528667142: New client connected from 45.232.92.159 as lens_HJ9OowTbqNS11toqxXxt4eFnFew (c1, k120, u’batman’).1528667142: Sending CONNACK to lens_HJ9OowTbqNS11toqxXxt4eFnFew (0, 0)

1528667150: Received PUBLISH from lens_HJ9OowTbqNS11toqxXxt4eFnFew (d0, q0, r0, m0, ‘dc/batman/test’, … (4 bytes))1528667155: Received SUBSCRIBE from lens_HJ9OowTbqNS11toqxXxt4eFnFew1528667155: dc/batman/test (QoS 0)1528667155: lens_HJ9OowTbqNS11toqxXxt4eFnFew 0 dc/batman/test1528667155: Sending SUBACK to lens_HJ9OowTbqNS11toqxXxt4eFnFew1528667159: Received PUBLISH from lens_HJ9OowTbqNS11toqxXxt4eFnFew (d0, q0, r0, m0, ‘dc/batman/test’, … (4 bytes))1528667159: Sending PUBLISH to lens_HJ9OowTbqNS11toqxXxt4eFnFew (d0, q0, r0, m0, ‘dc/batman/test’, … (4 bytes))1528667160: New client connected from 45.232.92.159 as baticueva (c1, k30, u’alliot’).1528667160: Sending CONNACK to baticueva (0, 0)1528667160: Received SUBSCRIBE from baticueva1528667160: dc/dc/batman/baticueva/# (QoS 1)1528667160: baticueva 1 dc/dc/batman/baticueva/#1528667160: Sending SUBACK to baticueva

1528667160: Sending SUBACK to baticueva
1528667190: Received PINGREQ from baticueva
1528667190: Sending PINGRESP to baticueva
1528667220: Received PINGREQ from baticueva
1528667220: Sending PINGRESP to baticueva

The logs depends in what kind of action are you doing with broker, you hace two main action, PUBLISH  where you send a message to the broker, and the other is SUBSCRIBE.

With any client you can set be a publisher or a subscriber. Keep in mind you have QoS , quality of service where determine how you can confirm your messages.

You can now connect to your mosquitto broker with your favorite client.

 

 

 

Links

WS Mosquito

Mosquitto ECLIPSE DOCS

Mosquitto docker file

MOsquitto Password Config

 

 

 

Flisol 2018 – Valparaiso – Chile

 

Flisol – 2018 – Valparaiso.

El evento transcurrió con un publico muy activo y participativo en la totalidad de sus charlas, por cuestiones de tiempo no se llego a dar  una única charla (Y si probamos OpenBSD). La sede donde se realizo contaba con todo lo que se necesita y mucho mas. Muy conforme con los organizadores y siempre que se necesito algo había alguien para contestar y acudir a nosotros.

 


 

 

 

Las charlas transcurrieron de forma natural, muy divertidas y participativas, tanto las técnicas como las mas sociales.

 

 

 

 

 

 

 

 

 

Y como no podia faltar, las instalaciones, en este caso con una Mac Mini, PowerPC  1.2Ghz, 1G Ram que tiene instalado Openbsd lo usamos de router para poder instalar las ademas laptops, en este caso instalamos un Fedora 28.

 

 

 

 

 

 

Hasta la próxima y a seguir colaborando!!!

 

 

Configurando nuestro prompt en bash

En este breve post vamos a ver como personalizar nuestra terminal para poder tener entre otras cosas, colores.
Lo primero que deberiamos mirar es el siguiente link para poder entender acerca de las diferentes posibilidades que tenemos:
ANSI ESCAPE CODE

Lo primero que deberiamos repasar es la variable mas significativa para el uso del prompt ( PS1 ).
Utilizando los siguientes valores de la tabla de ANSI podremos cambiar el color del a letra y el fondo:


Esc[Value;...;Valuem Set Graphics Mode

Foreground colors
30 Black
31 Red
32 Green
33 Yellow
34 Blue
35 Magenta
36 Cyan
37 White

Background colors
40 Black
41 Red
42 Green
43 Yellow
44 Blue
45 Magenta
46 Cyan
47 White

Utilizando algunos ejemplos:

[crond1@restauracion /etc]$ PS1="[\u-\V]\n[\w]$"
[crond1-4.2.24]
[/etc]$

En el ejemplo descripto arriba hemos seteado nuestro prompt para que nos de el nombre de usuario seguido de la version de bash, luego debajo tenemos el directorio donde estamos trabajando y el signo $ para terminar nuestro prompt.

Ahora podriamos ponerle algun color segun la norma ANSI:


[/etc]$LRED="\[\e[01;31m\]"
[crond1-4.2.24]
[/etc]$PS1="[${LRED}\u-\V]\n[\w]$"
[crond1-4.2.24]
[/etc]$

En este caso definimos una variable local que nos da el color rojo y aplica a todo lo que viene despues, por eso nos queda todo el prompt rojo salvo el primero corchete que dado que esta detras de la variable RED, los valores que estan dentro de la variable red tienen que ver con la forma que se escriben segun la tabla de ANSI.
Tener en cuenta que ahora todo lo que escribamos sera rojo, por eso conviene al final agregarle un valor por defecto como DEFAULT=”\[\e[0m\]” , quedando asi mi variable PS1=”[${LRED}\u-\V]\n[\w]$ ${DEFAULT} ”

[/etc]$DEFAULT="\[\e[0m\]"
[crond1-4.2.24]
[/etc]$PS1="[${LRED}\u-\V]\n[\w]$ ${DEFAULT} "
[crond1-4.2.24]
[/etc]$ pwd

Ahi lo tenemos configurado para que escriba todo lo demas con el color blanco.
Podriamos generar algun archivo con funciones para poder utilizar y cargar nuestros valores, pero primero vamos a probar algunos ejemplos:


[/etc]$ echo -e "${LRED}prueba"
\[\]prueba
[crond1-4.2.24]
[/etc]$ LRED="\[\e[01;31m\]"
[crond1-4.2.24]
[/etc]$ echo -e "${LRED}prueba"
\[\]prueba
[crond1-4.2.24]
[/etc]$
[/etc]$ LRED="\[\e[04;31m\]"
[crond1-4.2.24]
[/etc]$ echo -e "${LRED}prueba"
\[\]prueba
[crond1-4.2.24]
[/etc]$
[crond1-4.2.24]
[/etc]$ LRED="\[\e[07;31m\]"
[crond1-4.2.24]
[/etc]$ echo -e "${LRED}prueba"
\[\]prueba
[crond1-4.2.24]
[/etc]$

En los ejemplos anteriores lo que hicimos fue mostrar el texto con diferentes atributos:

Text attributes
0 All attributes off
1 Bold on
4 Underscore (on monochrome display adapter only)
5 Blink on
7 Reverse video on
8 Concealed on

Tambien nuestro bash interpreta ciertos codigos para mostrarnos algunos valores especificos utilizando los siguientes ejemplos:

Bash permite que esas cadenas de prompts sean personalizadas al insertar un
número de carácteres especiales de barra invertida de escape que son
decodificados como sigue:

\a un caracter de campana ASCII (07)
\d la fecha en formato "Día Mes Fecha" (p.ej., "Tue May 26" - Mar May 26)
\D{format} el formato es pasado a strftime(3) y el resultado
es insertado en la cadena del prompt. un formato vacío
resulta en un tiempo de representación específico del locale.
Se requieren los tirantes
\e un carácter de escape ASCII (033)
\h el nombre de anfitrión hasta el primer `.'
\H el nombre de anfitrión
\j la cantidad de trabajos actualmente manejados por el shell
\l el nombre base del nombre de dispositivo de la terminal del shell
\n línea nueva
\r retorno de carro
\s el nombre del shell, el nombre base de $0 (la porción siguiendo
la barra final)
\t el tiempo actual en un formato de 24-horas HH:MM:SS
\T el tiempo actual en un formato de 12-horas HH:MM:SS
\@ el tiempo actual en un formato de 12-horas am/pm
\A el tiempo actual en un formato de 24-horas HH:MM
\u el nombre de usuario del usuario actual
\v la versión de bash (p.ej., 2.00)
\V la liberación de bash, versión + nivel de parche (p.ej., 2.00.0)
\w el directorio de trabajo actual, con $HOME abreviado con una tilde
\W el nombre base del directorio de trabajo actual, con $HOME
abreviado con una tilde
\! el número de historial de este comando
\# el número de comando de éste comando
\$ si el UID efectivo es 0, un #, de lo contrario un $
\nnn el carácter correspondiendo al número octal nnn
\\ una barra inversa
\[ comienza una secuencia de carácteres no imprimibles, los cuales podrían ser usados
para embeber una secuencia de control de terminal en el prompt
\] terminar una secuencia de carácteres no imprimibles


Con estos codigos podemos hacer que nuestro prompt nos devuelva informacion importante segun el uso que le quiseramos dar.

Teniendo en cuenta todo lo anterior podriamos armarnos nuestras reglas en nuestro profile para utilizar el prompt como deseemos.

Creamos el siguiente archivo en nuestro $HOME.

ARCHIVO --> .prompt
#!/bin/bash

prompt_path_set()
{
CWD=${PWD}

local COUNT_SPACE_OVER=$((${#CWD}-${PATH_WIDTH}+3))
if [ ${COUNT_SPACE_OVER:-0} -ge 0 ] ; then
TMP=''
while [ ${COUNT_SPACE_OVER:-0} -ne 0 ]
do
COUNT_SPACE_OVER=$((${COUNT_SPACE_OVER}-1))
TMP="?${TMP}"
done

CWD="...${CWD#${TMP}}"
fi
}

PROMPT_COMMAND=precmd
precmd()
{
#############
#COLOR CODES#
#############
local PATH_WIDTH=$((${COLUMNS:-80} / 4))
local DEFAULT="\[\e[0m\]"
local BOLD="\[\e[1m\]"
local HIDDEN="\[\e[8m\]"
local BLACK="\[\e[00;30m\]"
local GRAY="\[\e[01;30m\]"
local RED="\[\e[00;31m\]"
local LRED="\[\e[01;31m\]"
local GREEN="\[\e[00;32m\]"
local LGREEN="\[\e[01;32m\]"
local BROWN="\[\e[00;33m\]"
local YELLOW="\[\e[01;33m\]"
local BLUE="\[\e[00;34m\]"
local LBLUE="\[\e[01;34m\]"
local PURPLE="\[\e[00;35m\]"
local LPURPLE="\[\e[01;35m\]"
local CYAN="\[\e[00;36m\]"
local LCYAN="\[\e[01;36m\]"
local LGRAY="\[\e[00;37m\]"
local WHITE="\[\e[01;37m\]"
local BARRAPESOS="\\$"
local CWD
local TMP

prompt_path_set

PS1="${CYAN}[${LGRAY}\t${CYAN}]\n${CYAN}[${WHITE}${BOLD}\h${YELLOW}@${LBLUE}${CWD} ${LCYAN}${BARRAPESOS}${CYAN}]${DEFAULT} "

# ESC DESCRIPTION
# \a an ASCII bell character (07)
# \d the date in "Weekday Month Date" format (e.g., "Tue May 26")
# \e an ASCII escape character (033)
# \h the hostname up to the first `.'
# \H the hostname
# \j the number of jobs currently managed by the shell
# \l the basename of the shell's terminal device name
# \n newline
# \r carriage return
# \s the name of the shell, the basename of $0 (the portion following the final slash)
# \t the current time in 24-hour HH:MM:SS format
# \T the current time in 12-hour HH:MM:SS format
# \@ the current time in 12-hour am/pm format
# \u the username of the current user
# \v the version of bash (e.g., 2.00)
# \V the release of bash, version + patchlevel (e.g., 2.00.0)
# \w the current working directory
# \W the basename of the current working directory
# \! the history number of this command
# \# the command number of this command
# \$ if the effective UID is 0, a #, otherwise a $
# \nnn the character corresponding to the octal number nnn
# \\ a backslash
# \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
# \] end a sequence of non-printing characters
}

Luego en nuestro .bashrc agregamos la siguiente linea:


echo ". ${HOME}/.prompt" >> $HOME/.bashrc

Mirando mas profundamente la documentacion vemos que son muchas las variantes que podemos hacer pero lo ideal es ir probando lo mas basico para ir asimilando como funciona asi luego avanzar con los parametros mas avanzados.

Fuentes:
ANSI ESCAPE CODE
Bash Tutorial
TLDP
Bash-How-To
PS1 Examples
Color_Bash_Prompt/es
bash-power-prompt