Bluemix Connection Refused: not authorised, can't register device - ibm-cloud

I have read several tutorials and topics and I did everything as described, but still I am not able to register device.
I have been trying to use MQTTlens and mosquitto but same problem, not authorised
Bellow is command for mosquitto
mosquitto_pub -h xwc8vm.messaging.internetofthings.ibmcloud.com -u use-token-auth -P 'YpSP?P98Wwe0pYGXPj' -i 'd:xwc8vm:devicetype:mydevice' -t /iot/x -m '{"d":"heloo"}'
This are devices data
Organization ID xwc8vm
Device Type devicetype
Device ID mydevice
Authentication Method token
Authentication Token XXXXXXXXXX
I have used host
xwc8vm.messaging.internetofthings.ibmcloud.com
and client
d:xwc8vm:devicetype:mydevice
I even tried using http://mqtt-helper.mybluemix.net/?cm_sp=dw-bluemix--nospace--answers, but got this error
(23:42:45.044)Failed to connect to xwc8vm.messaging.internetofthings.ibmcloud.com:1883. Code: 1, Message: AMQJSC0001E Connect timed out.
Everything is configured as here http://heidloff.net/article/useful-mqtt-tools-ibm-watson-iot-bluemix?cm_mc_uid=27677244132415055778021&cm_mc_sid_50200000=1505944109

You can check your TLS security setting in your dashboard under the security tab. New IoT services by default require TLS. If you are not using TLS then try setting it to optional to see if that resolves the problem.

The mosquito command is not complete, you need to specify the port 8883, and the connection is secure by default and you need to specify the server certificate that can be downloaded from below:
https://github.com/ibm-watson-iot/iot-python/blob/master/src/ibmiotf/messaging.pem
So the command should look like:
mosquitto_pub -h xwc8vm.messaging.internetofthings.ibmcloud.com -p 8883 -u "use-token-auth" -P "xxxxxxxxx" -i "d:xwc8vm:device-type:my-device" -t "iot-2/evt/x/fmt/json" -m {"d":"hello"} --cafile messaging.pem -d
messaging.pem file needs to be in the same location as mosquitto_pub file or you can pass the path to it
Note: Please mind the topic format:
"iot-2/evt/x/fmt/json" >>>>> iot-2/evt/event/fmt/event_format
Very important, please edit your post and remove or mask the authentication token

Related

gcloud beta sql connect "server closed the connection unexpectedly"

When trying to get a psql shell (not using iam user) I am receiving:
> gcloud alpha sql connect pg-instance --database mydb --user myuser --project my-project
Starting Cloud SQL Proxy: [/Users/me/google-cloud-sdk/bin/cloud_sql_proxy -instances my-project:us-central1:pg-instance=tcp:9470 -credential_file /Users/me/.config/gcloud/legacy_credentials/me#me.com/adc.json]]
2022/03/15 14:47:59 Rlimits for file descriptors set to {Current = 8500, Max = 9223372036854775807}
2022/03/15 14:47:59 using credential file for authentication; path="/Users/me/.config/gcloud/legacy_credentials/me#me.com/adc.json"
2022/03/15 14:48:00 Listening on 127.0.0.1:9470 for my-project:us-central1:pg-instance
2022/03/15 14:48:00 Ready for new connections
Connecting to database with SQL user [myuser].Password:
psql: error: connection to server at "127.0.0.1", port 9470 failed: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
I had the same error message when connecting to Postgres(Cloud Sql) using a service account.
In my setup I did run cloud_sql_proxy inside docker container.
In order to make it work I had to add extra configuration defined in step #9 https://cloud.google.com/sql/docs/sqlserver/connect-docker#connect-client
docker run -d \
-v <PATH_TO_KEY_FILE>:/config \
-p 127.0.0.1:5432:5432\
gcr.io/cloudsql-docker/gce-proxy:1.33.1 /cloud_sql_proxy \
-instances=<INSTANCE_CONNECTION_NAME>=tcp:0.0.0.0:5432 -credential_file=/config
The missing bits were: host ip on port mapping and 0.0.0.0: in cloud_sql_proxy command
There are a few things I would like to point out. The best starting point for me would be the About connection options page; both the Overview and the Before you begin sections are very helpful to get the full idea of the process and how to properly configure the user. But the most important part is the Connection Options, for the message connection to server at "127.0.0.1" I’m guessing it is a private IP, but please make sure this section is covered before starting to debug.
In your case, the logs are saying there was an error in the connection to the server…
I used the Troubleshoot guide that includes the Diagnose issues link to get to the Debug connection issues page that has a lot of useful information on how to debug any connectivity issue.
Generally, connection issues fall into one of the following three areas:
Connecting - are you able to reach your instance over the network?
Authorizing - are you authorized to connect to the instance?
Authenticating - does the database accept your database credentials?
Each of those can be further broken down into different paths for investigation.
Once determining the connection method, there are different questions that will help to guide you through the possible troubleshooting paths.
If using these guides doesn’t get you a solution, please make sure to update your answer with the results, steps, and information followed to provide further help. This would be a good example, as it has the same log error, and this other question shows that there are a few different troubleshooting paths for this specific log message, plus they have useful information for you.

Publish message to kapua using kura or MQTT

I am working on an IoT device. I have installed Eclipse Kura in raspberry pi 3
to use it as a gateway. I want to publish a message to Kapua server (installed in the same network) using Kura or directly using the raspberry pi. I have tried both methods.
1- Using Kura
I have followed the given instructions on GitHub Kura Kapua connection tutorial #780. After following these steps I am able to establish the Kura Kapua connection but unable to send data, Example.publisher package is also installed in Kura. I want to create a topic and publish data on that topic.
2- Using MQTT-Client library
I have installed the MQTT-Client library in raspberry pi and use the following commands to publish and subscribe the data.
To Publish :
sudo mosquitto_pub -h "broker-URL" -p "Port" -t "topic" -m "message" -u "user-name"-P "user-pass" -i "client-id"
To subscribe :
sudo mosquitto_pub -h "broker-URL" -p "Port" -t "topic" -u "user-name"-P "user-pass" -i "client-id"
this has the same behavior, It also establishes the connection but unable to create the topic and publish data.When I do the same for localhost it does send the message. I am using two different terminals to publish and subscribe.
Is there any method or example where I can actually send some data and observe at the other end using Kura or MQTT.
General knowledge
Correct connection parameters (if you followed the tutorial you mentioned) are:
-h localhost
-p 1883
-u kapua-broker
-P kapua-password
(not sure the doublequote is required)
Kapua uses has a specific topic format to grant access control over the topics.
The semantic of the format is:
{account-name}/{client-id/{semantic-topic}
Depending on your privileges you can access different levels of topics.
The defaults user kapua-broker allows only to connect, publish and subscribe under:
{kapua-sys}/{connection-client-id}/#
You need more permissions to subscribe to other client-id topics.
The permission required to do that is:
data:view
Your example
First, it seems that you are using the published to subscribe. This is your command.
sudo mosquitto_pub -h "broker-URL" -p "Port" -t "topic" -u "user-name"-P "user-pass" -i "client-id"
Secondly credential, host, usenrname, password, and topic are all wrong (unless you "obscured" them before publishing to SO).
To make your test work you need to use the following commands,
Subscribe
mosquitto_sub -h "localhost" -p "1883" -t "kapua-sys/mosquitto_pub/my/test/topic" -u "kapua-sys" -P "kapua-password" -i "mosquitto_sub"
Publish
mosquitto_pub -h "localhost" -p "1883" -t "kapua-sys/mosquitto_pub/my/test/topic" -m "My test message" -u "kapua-broker" -P "kapua-password" -i "mosquitto_pub"
For the Kura example publisher, I don't know where could be the problem, due to lack of info. I'm assuming you are publishing or subscribing to a topic you cannot access to due to write/read permission on topics.
Hope that this help! :)

IBM watson internet of things platform: Connecting using client certs & mosquitto client

I get below error while trying to connect to IBM Watson internet of things platform using client certs & mosquitto client. The same certs work fine with node.js client hence I know certs are fine, just some config in mosquitto client which is erroneous.
mosquitto_sub -h dumorg.messaging.internetofthings.ibmcloud.com -p 8883 --capath ./certs/ -t "iot-2/type/dumtype/id/dumid/cmd/+/fmt/json" -v -i g:dumorg:dumtype:dummid --cert ./client.crt --key ./client.key
Connection Refused: not authorised.
When I try to perform same connection using auth-token it goes through fine
$ mosquitto_sub -h dumorg.messaging.internetofthings.ibmcloud.com -p 8883 --capath ./certs/ -t "iot-2/type/dumtype/id/dumid/cmd/+/fmt/json" -v -i g:dumorg:dumtype:dumid -P dumpassword -u use-token-auth
I am also able to successfully connect using certs through another client. I know the certs are fine, and mosquitto command works with auth token. hence issue is some missing/incorrect config in mosquitto due to which IoT platform doesn't like certs used to connect with mosquitto?
Seems mosquitto does not support SNI which is required to connect to MQTT broker on IBM cloud. Manually inserting this patch https://github.com/eclipse/mosquitto/pull/626 and building mosquitto resolved issue. Hope this is merged in main branch in near future.

postgresql: pg_ctl status shows no server running when the server is running as a windows service

I have PostgreSQL 9.4(not installed, rather self configured) which is also installed as a Windows service. Now I am trying to check the status of the server using pg_ctl.exe status -D data_dir_path, but it only shows the status when I start the console as admin.
My final goal is to be able to shutdown/ start the database server without admin rights. Is it possible to configure PostgreSQL so that I can start/stop the servers locally without admin rights?
As far I read in the PostgreSQL documentation, the services can be registered to a user using [-U username] [-P password] arguments but I am not sure whether this is the database user or the local windows user. I tried registering the service using the following code but it does not install it. And I do not see any logs too. The commnd follows:
pg_ctl.exe register -N service_name -U database_user -P database_user_password -D data_dir_path -S auto -o "-p port"
Thanks in advance

What are the Curl SMTP command line arguments to support GMail TLS/STARTTLS vs SSL

I am using Curl.exe in an application to send emails. I need to support most major email servers. GMail exposes the following ports and Authentication methods.
TLS/STARTTLS (sometimes called Explicit TLS): uses port 587
SSL (sometimes called Implicit TLS): uses port 465
I have gotten the Explicit TLS to work using the following command line:
C:\>curl smtp://smtp.gmail.com:587 -v --mail-from "my.mail#gmail.com" --mail-rcpt
"your.mail#x.com" --ssl -u my.mail#gmail.com:password -T "c:\test.txt" -k --anyauth
I have tried the following to get ImplicitTLS to work, but it is not.
C:\>curl smtp://smtp.gmail.com:465 -v --mail-from "my.mail#gmail.com" --mail-rcpt
"your.mail#x.com" --ssl -u my.mail#gmail.com:password -T "c:\test.txt" -k --anyauth
What are the proper command line parameters to get SSL/Implicit TLS to work?
Use smtps:// for SMTPS (i.e. SMTP on top of an existing SSL/TLS connection).
This works:
curl smtps://smtp.gmail.com:465 -v
I would also use --ssl-reqd for the explicit STARTTLS connection to make sure SSL/TLS is used when you expect it to be (downgrade attacks would be possible otherwise).
Don't use -k either, check the server certificate: see http://curl.haxx.se/docs/sslcerts.html
well i just tried the following and it works fine:
curl smtps://smtp.gmail.com:465 -v --mail-from "xxx#gmail.com" --mail-rcpt "yyy#gmail.com" --ssl -u xxx#gmail.com:password -T "test.txt" -k --anyauth
hope it helps!
Your can try this..
curl --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender#gmail.com" --mail-rcpt "recepient#gmail.com" --upload-file /var/scripts/mail.txt --user "sender#gmail.com:senderGmailPassword"
You can test using this command:
curl -v --url "smtps://smtp.gmail.com:465" --ssl-reqd --mail-from "sender#gmail.com" --user "sender#gmail.com" --mail-rcpt "sender#gmail.com"
You will have to create a new 16 digits password specific for this application and simply change the account password to this new secure app password. Now you can create one password for each app. It will keep your account password safe and manage app passwords separately.
Login to your account to create it:
https://myaccount.google.com/apppasswords
You must enable the 2-Step Verification (https://myaccount.google.com/signinoptions/two-step-verification) to access this feature.
To help keep your account secure, from May 30, 2022, ​​Google no
longer supports the use of third-party apps or devices which ask you
to sign in to your Google Account using only your username and
password.
https://support.google.com/accounts/answer/6010255