How to subscribe a Watson IoT Device events using MQTT? - ibm-watson

I'm creating a MQTT client with Paho and Python to connect with a device in Watson IoT Platform.
I correctly assembled the broker:
<org>.messaging.internetofthings.ibmcloud.com:1883
And the client:
d:<org>:<type>:<deviceId>
And published values to this topic:
iot-2/evt/<eventName>/fmt/json Payload: {"db",56}
With the authentication:
username: use-token-auth Password:
And all OK.
But I tried to subscribe the topic iot-2/type//id//evt//fmt/json
And the connection always closes, and the dashboard says:
Closed connection. The topic is not valid: iot-2/type/sound/id/ipt/evt/db/fmt/json The topic does not match an authorized rule
Why this don't work? Thank you

You cannot subscribe to an events topic using using a clientID of "d:::". You need to generate an APIKey and use a clinetID of "a:orgId:appId" to subscribe to topic iot-2/type/device_type/id/device_id/evt/event_id/fmt/format_string (iot-2/type/sound/id/ipt/evt/db/fmt/json)
You can use as reference: https://www.ibm.com/support/knowledgecenter/SSQP8H/iot/platform/applications/mqtt.html

Related

Discord Interprocess Communication - Read Messages

I'd like to abide by TOS but i am having tough time. I'm in paid server where I can't place a bot account. I simply want to consume the message content in my application (currently in python). What can I do? Can I write a hook to consume the messages from the GUI or from the web client? It seems what I want to do is not supported. Any thoughts?
Others have stated that you can apparently use use ipc and messages.read scope or RPC to receive messages but I don't know what resources are available to hook into and get the message content as it comes from the server.
There are multiple ways to read the messages from the client. You could use the Discord API with your account's token, but this is not allowed by the Discord ToS and thus is bannable (self botting). The other way is to use Discord IPC.
Discord IPC allows you to communicate with the Discord client by using named pipes. The default name is discord-ipc-0. You need a Discord application to use it.
The IPC protocol uses the same protocol as RPC, which is documented on Discord Developer Portal. You can also find more information on the IPC protocol on the discord-rpc official repo.
To put it simply, the packets you send through the pipe are serialized that way:
uint32 opcode
uint32 length
byte[length] jsonData
The data is a JSON encoded object, with a unique nonce parameter that is sent back on the answer, a cmd parameter for the command you want to use and optionally args and evt.
You would probably be interested in the AUTHORIZE, AUTHENTICATE, GET_CHANNEL and SUBSCRIBE commands. So I'll explain those four commands here.
But first, you need to connect to the IPC and do the handshake. This is done by sending a message with the opcode 0, your client_id and the protocol version. Here's what the JSON object should look like:
{
"v": 1,
"client_id": 332269999912132097
}
Once you're connected, you should receive a DISPATCH response with the user info. Every message you will send from this point should use the opcode 1
Now, you need to send an AUTHORIZE command This command allows you to ask an OAuth2 code from the client with the specified scopes, which will allow you to use the AUTHENTICATE command. Here, you would want the rpc and messages.read scopes. It should look like this:
{
"nonce": "be9a6de3-31d0-4767-a8e9-4818c5690015",
"cmd": "AUTHORIZE",
"args": {
"client_id": 332269999912132097,
"scopes": "rpc messages.read"
}
}
Please note that you need a redirect uri on your application for this to work.
The client should get a prompt. If he accepts, then your application would receive an oauth2 code that you can use to authenticate. The OAuth2 process is explained on the Discord Developer Portal.
After making your request to /oauth2/token with the code, your client id, client secret and redirect uri, you should be getting an access token that you can to authenticate, using the AUTHENTICATE command. Here is what it should look like:
{
"nonce": "5dc0c062-98c6-47a0-8922-bbb52e9d6afa",
"cmd": "AUTHENTICATE",
"args": {
"access_token": "CZhtkLDpNYXgPH9Ml6shqh2OwykChw"
}
}
If the authentication is successful, you should receive a response with evt set to null, application info and user info.
From this point, you are authenticated and you can read messages by using the GET_CHANNEL command to get the last messages, and by subscribing to the MESSAGE_CREATE event to get the new messages when they're sent. Those are documented on the Developer Portal.

Gmail - get mailbox delegations in latest API

I am attempting to get a list of mail delegates for each user within a domain on gmail to display to our users at www.rulerr.com . I am authenticating as a service account with domain wide delegation. I pull a list of users, and then authenticate using the service account as each user in the domain to access their gmail data.
Unfortunately it looks like I cannot access delegation information with the latest API, but the functionality exists in the old (now deprecated) API. When will this functionality be moved to the latest API? Or is there a different endpoint that I should be using?
I have also attempted to work around this by delegating user B's gmail to user A, authenticating as user A and then attempting to list messages within user B's mailbox which results in an error:
{ [Error: Delegation denied for <email redacted>]
code: 403,
errors:
[ { domain: 'global',
reason: 'forbidden',
message: 'Delegation denied for <email redacted>' } ] }
Thanks for your help.
As of now we will just have to wait for the Gmail API to add the delegation feature from the deprecated Email Settings API:
Managing delegation
settings
Delegation settings are not yet available via the API.
Disclaimer: I work on Gmail and the Gmail API platform.
Managing Delegation Settings
We're happy to announce that we have now released the new Gmail API delegate settings methods, effectively replacing the long since deprecated Email Settings API delegation settings methods.
You can now use the standard libraries and tools found at https://developers.google.com/gmail/api to interact with the new Gmail delegate settings methods.
We will be publishing a blog post at https://gsuite-developers.googleblog.com raising the visibility of the new delegate settings methods in the coming weeks, but I wanted to personally give you a courtesy heads-up.
Documentation
Overview/introduction guide:
https://developers.google.com/gmail/api/guides/delegate_settings
Reference documentation: https://developers.google.com/gmail/api/v1/reference/users/settings/delegates
Migration guide (from the deprecated Email Settings API delegation settings methods):
https://developers.google.com/gmail/api/guides/migrate-from-email-settings#managing_delegation_settings

Sending Image/File/Audio Files to Browser via websockets/http using mongoose

I am using Mongoose library to have a localhost server run in my system.
Now, through HTTP Connection OR Websocket Connection, I want to send files/documents/images/small audio files to the client who is making request to the local host.
Until now i was sending a simple json message via websockets and xml data via http connection to client (Browser) by using these Mongoose APIs
mg_send_data()
mg_websocket_write()
Since Mongoose is being used the whole implementation is in C
Kindly let me know if I can refer to any of the example code if there are any, OR any API documentation of Mongoose which would help me to achieve the above.
Looking forward for valuable responses.
From the github repository you will find :
the API documentation
severals samples that show how to implement websocket and sending MJPEG

Hotmail/Outlook.com connection failure on AUTH commands

I'm working on an embedded application (running MQX RTOS, written in C) which has SMTP functionality. Recently, TLS support was added using the Mocana NanoSSL library. I'm currently able to successfully send emails using Gmail, Yahoo, and private exchange servers. Unfortunately, Hotmail does not work. Here's the connection parameters i've used:
Server: smtp.live.com
Port: 25 and 587
AUTH method: PLAIN and LOGIN
Basically, i'm able to successfully connect to the server, perform the SSL/TLS handshake (using STARTTLS), and send the encrypted EHLO message to the server (receiving a response). According to this response, the server supports both AUTH PLAIN and AUTH LOGIN. However, once I send either of these commands, the following SSL_recv() call I make to get the response fails with either a timeout or connection reset by peer.
UPDATE:
OK, so after some experimentation it would appear that my issue lies at the SSL library level and not with Microsoft's SMTP server. I tried replacing the SSL_recv() calls with standard RTCS socket recv() calls and was able to receive and view encrypted data. By disabling my response verification, I was then able to continue through the SMTP process and successfully send a message. At this time i'm not sure why the SSL_recv() calls are unable to get the socket data, but i'll keep digging and will hopefully find an answer.
Well, I also got it working here too. I had to replace the
ssl_ctx=SSL_CTX_new(SSLv23_client_method());
with either:
ssl_ctx=SSL_CTX_new(SSLv3_client_method());
or
ssl_ctx=SSL_CTX_new(TLSv1_client_method());
My understanding is that the 23_client method sends a SSL2 client hello first and this confuses the server.
I read this in the HP SSL programming tutorial:
http://h71000.www7.hp.com/doc/83final/ba554_90007/ch04s03.html
it says: "However, the SSL client using the SSLv23 method cannot establish connection with the SSL server with the SSLv3/TLSv1 method because SSLv2 hello message is sent by the client."
SSL3 works too since you can continue after STARTTLS with SSL, you do not have to use TLS.
See here:
https://www.fastmail.fm/help/technology_ssl_vs_tls_starttls.html
So, it's the SSL library itself that appears to be failing me here. I was able to bypass the issue and successfully send email by simply not calling SSL_recv() to verify the server responses. I'm obviously not able to error check or get any meaningful failure feedback, but for a successful use case where the server accepts all of my SMTP messages the email is sent.

Receive mails through a port and extract body and headers

I am trying to build a proxy server in between my application and my smtp server. So when my application sends an email to some email id, my proxy server should catch it and change its "TO" address to my id and then send it to smtp server so that I'll get that message in my mail. This is a different case compared to reading messages from an inbox. I dont know how to distinguish each separate mail and get mail headers and body from each mail.
Any help would be greatly appreciated. Thanks in advance!
You should take a general look at JavaMail API and playing with it before asking for complete solutions.
Some other resources:
jGuru: Fundamentals of the JavaMail API
the JavaMail API - FAQ

Resources