Arduino POST vs GET request - post

I have a bunch of temperature data my Arduino monitors that I want to put into a Google Fusion table. Fusion tables require OAuth for record inserts which the Arduino can't handle (I don't think), I want to create a little app Google's App Engine that will receive the data from the Arduino, then this app will authenticate with the Fusion table and insert a record. Each record would have about 65 fields. I don't know how to do the app on Google App Engine yet, but I'll figure that our separately. What I'd like to know is the pros and cons of sending the data to the app using a GET request or a POST request from my Arduino. For this scenario, is one a better choice then the other?

You will need to use an HTTP POST request if you are wanting to send data from the Arduino.
The difference between the two is that GET is for requesting data from the server, while POST is for sending data to the server.
Here is a link for information about HTTP Message Types:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
Now for the Arduino code, you need to do the following to send the POST request using the GSM Shield.
//First, establish a connection to the cell tower via GSM
String PIN = "123456"; //The PIN of your SIM card
gsmAccess.begin(PIN);
//Next, connect to your service provider's GPRS network (internet access)
String GPRS_APN = "The APN of your provider";
String GPRS_LOGIN = "Your login name";
String GPRS_PASSWORD = "Your password";
gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD);
//Now you need to connect a client to your GAE web server on port 80
client.connect("ServerName", 80);
//Now send the properly-formed HTTP POST request
String message = "The message body of the request, the data you want to send";
client.print("POST ");
client.print("/yourPathToDesiredPage");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println("ServerName");
client.println("Content-Type: text/plain");
client.print("Content-Length: ");
client.println(message.length());
client.println();
client.println(message);
client.endWrite();

Related

WhatsApp audio media message (MediaUrl0) Transcribe to text

I have a dialogflow chatbot that communicates with Whatsapp for business users, thru Twilio.
I would like to enhance the "chat" chatbot capability, and allow whatsapp users to also be able to send a voice messages.
WhatsApp voice media messages sent to Twilio have a URI parameter with the location of the media file, but this URI does not have a file extension. How can i extract the file to send it to a Speech-to-text service (Google or AWS) to have it transcribed into text and then send it to Dialogflow for intent recognition
Any ideas how i would go about doing this?
Twilio message log for a media message:
Request Inspector
+ Expand All
POST
https://xxxxxxxxxxxx
2021-04-27 08:35:39 UTC502
Request
URL
ParametersShow Raw
MediaContentType0 "audio/ogg"
SmsMessageSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
NumMedia "1"
ProfileName "xxxxx"
SmsSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
WaId "xxxxxxxxx"
SmsStatus "received"
Body ""
To "whatsapp:+32460237475"
NumSegments "1"
MessageSid "MMea4e6bcb3a9654a03d8d2a607c6d4cdd"
AccountSid "ACef27744806d8f8e68f25211b2ba8af60"
From "whatsapp:+32474317098"
MediaUrl0 "https://api.twilio.com/2010-04-01/Accounts/ACef27744806d8f8e68f25211b2ba8af60/Messages/MMea4e6bcb3a9654a03d8d2a607c6d4cdd/Media/ME27fbc66d47d8de49f1ae00e433884097"
ApiVersion "2010-04-01"
Message TextShow Raw
sourceComponent "14100"
httpResponse "502"
url "https://xxxxxxxxx"
ErrorCode "11200"
LogLevel "ERROR"
Msg "Bad Gateway"
EmailNotification "false"
I think you don't need the extension for this use case, you will probably need the language code for the resulting text and may be, AudioEncoding and sample rating for the transcription service.
Here is some examples from my code for whatson / google coud speech to text and DialogFlow.. AWS and Microsoft are very similar
//for ibm watson
RecognizeOptions recognizeOptions = new RecognizeOptions.Builder()
.model(RecognizeOptions.Model.ES_ES_NARROWBANDMODEL)
.audio(new ByteArrayInputStream(bytes))
.contentType(HttpMediaType.AUDIO_WAV)
.build();
// google speech to text
RecognitionConfig config = RecognitionConfig.newBuilder()
.setSampleRateHertz(48000)
.setLanguageCode(langcode)
.setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS)
.build();
// Dialogflow (sending audio directly)
InputAudioConfig inputAudioConfig = InputAudioConfig
.newBuilder()
.setLanguageCode(langcode)
.setSampleRateHertz(sampleRateHertz)
.build();
In the end, in all cases, what you send to the service is not a file but an array of byte (sort of)
Anyway, even when there is no one to one relation between content Type and file extension, the parameter "MediaContentType0" in the request give you a good starting point: "audio/ogg".

How to get solace queue statistics from Solclient API? c#

I am looking to retrieve some Solace queue stats e.g. the current messages spooled count out of the maximum limit for us to set a threshold to stop publishing more messages to the queue.
Also, to subscribe to vpn events to track message discard rates.
By the time we receive errors e.g. MaxMsgUsageExceeded/SpoolOverQuota, it will be too late.
I can't seem to find any of these on SolaceSystems.Solclient.Messaging API
https://docs.solace.com/API-Developer-Online-Ref-Documentation/net/html/7f10bcf6-19f4-beff-0768-ced843e35168.htm
Would be great if someone could help
(using C# for this)
To poll for Solace queue stats from your C# application, you could use legacy SEMP over the message bus to make a SEMP request for the details that you want. Semp (Solace Element Management Protocol) is a request/reply protocol that uses an XML schema to identify all managed objects available in a message broker. Applications can use SEMP to manage and monitor a message broker.
To allow for legacy SEMP to be used over the message bus, as opposed to the management interface, it first needs to be enabled on the Solace PubSub+ message broker at the VPN level.
To publish a SEMP request with the Solace .Net Messaging API, perform the following steps:
Create a Session.
Create the message topic. “#SEMP//SHOW”
ITopic topic = ContextFactory.Instance.CreateTopic( “#SEMP/<router name>/SHOW”);
Create a request message and set its Destination to the topic in Step 2:
IMessage requestMsg = ContextFactory.Instance.CreateMessage();
requestMsg.Destination = topic;
Set the SEMP request string as the binary attachment.
string SOLTR_VERSION = "8_4_0" //change to the message-broker's version
string SEMP_SHOW_QUEUE = "<rpc semp-version=\"soltr/" + SOLTR_VERSION +
"<show><queue><name>queueName</name><detail></detail></queue></show></rpc>";
requestMsg.BinaryAttachment = Encoding.UTF8.GetBytes(SEMP_SHOW_QUEUE);
Call the SendRequest(…) method on Session.
IMessage replyMsg;
ReturnCode rc = session.SendRequest(requestMsg, out replyMsg, timeout);
The SEMP response is returned in replyMsg.
Obtain the binary attachment data from the reply message:
replyMsg.BinaryAttachment
The binary attachment contains the SEMP reply for the command topic in the publish request.
The Solace PubSub+ message broker does raise an event when an egress message is discarded. However, it is only sent out approximately once every 60 seconds for the specified client so it is not possible to get these exact rates.
It is possible for your .NET application to subscribe to VPN-level events over the message-bus. To do this, you must first enable the Solace PubSub+ message broker to publish the events. You can then subscribe to the special topic and receive the events as messages.
The topic to subscribe to is:
#LOG/<level>/VPN/<routerName>/<eventName>/<vpnName>
The different levels can use the * wildcard. For example, if you wish to subscribe to all VPN events of all levels for the VPN apple on router QA-NY1, the topic string would be:
#LOG/*/VPN/QA-NY1/*/apple
SEMP (starting in v2) is a RESTful API for configuring, monitoring, and administering a Solace PubSub+ broker.
1-The swapper page link is SEMP V2 API
2-The Swagger metadata definitions URL is located # http://{solace-sever-url}/SEMP/v2/config/spec
3- From Visual studio, add REST API Client
4-In the configuration dialog pass swagger metadata URL (defined at step 2), for code purpose I choose SolaceSemp as input value parameter for client namespace input.
4 Once you click ok, VS will create the client along with the models under SolaceSemp namespace
5 Start using the client as per following
using SolaceSemp;
using Microsoft.Rest;
var credentials = new BasicAuthenticationCredentials();
credentials.UserName = "place user name";
credentials.Password = "place password";
using (var client = new SolaceSempClient(credentials))
{
var model = client.GetAboutApi();
}

SignalR with MVC

The requirement in our project is, Web UI(MVC 5) will place a request to adapter(intermediate layer) which takes 3-4mins to process the request and computes response. This response needs to be pushed back to UI. We are planning to implement Signalr for posting back the response to UI. I did a small POC on SignalR to open connection and to call a method from javascript and get response back. how can I push the data from server to client(once connection is set), no call from javascript/Web for requesting the response?.
To push datas from the server to the client the basic usage is :
On the client side :
var myHub = $.connection.CustomHub;
myHub.client.myFunction= function (param) {
alert(param);
};
On the server side :
Clients.All.myFunction("parameter");
To find more infos about signalr take a look here :
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr
You can download the light chat project in the page it's a good start.
Get Hubcontext of the application
IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext('HubName');
On top of hubcontext can broadcast message to all the clients or groups or to specific client based on connection Id
hubContext.Clients.Client(connectionId).JavaScript function(data)

How SignalR manages connection between Postbacks

1> Just want to understand how SignalR 1.x functions in a particular scenario
Lets say we have a 10 clients connected to Hub and one of the connected clients say client-1 performs a postback so OnDisconnected is called than OnConnected is called right ?
What happens if during this phase if client-2 try's to send message to client-1 exactly between the said scenario ie (msg is sent after client-1 is disconnected and before connected again )will client-1 miss the message or there's internal mechanism which makes sure client-1 does not miss the message sent by client-2
2> Second query I have is that I'm trying to pass a querystring using following code
var chat = $.connection.myHub;
$.connection.myHub.qs = { "token": "hello" };
but not able to retrieve it on the server side from the Context object
using
Context.QueryString.AllKeys
I even tried
var chat = $.connection.myHub;
$.connection.myHub.qs = "token=hello" ;
But it does not work ie when I check the keys, token is not present in AllKeys
Will appreciate if someone just help me out.
1: If a postback occurs a client will disconnect and then connect. However, when the client performs a connect again it will have a different Connection Id than it had prior to the postback. Therefore, any message sent to the old connection id will be missed because when the users browser connects again it will be known as a different client.
2: You're trying to set the query string on the hub proxy, not the connection. What you should be doing is:
$.connection.hub.qs = { foo: "bar" };

BlackBerry Push Service SDK - BPS server URL

In order to understand how the Push service in BlackBerry is implemented, I have installed the Push Service SDK and following the Push_Service_SDK-Getting_Started_Guide. Following ths steps thoroughly, on "Registering" myself from the app, I got the following error:
Request to register failed. Caused by java.io.IOException: Network operation [Subscribe] failed. Make sure that Content Provider URL is accesible.
Can anyone guide me through this. When keying in the details, we need to provide the "BPS server URL" and "Push Initiator application URL". I have received the credential details from BlackBerry and it contains PPG Base Url as "cpXXX.pushapi.eval.blackberry.com" where the XX needs to be replaced by the CPID (Content Provider ID). Is this link to be keyed in for "BPS server URL" and "Push Initiator application URL"? I did key in this and received the above error on "Register".
Please guide.
You should have received a mail with your credentials for both server app and blackberry client app. For the client app, they should look like this:
Application ID: <CPID(4 chars)>-<id(35 chars)>
PPG Base URL: http://cpXXX.pushapi.eval.blackberry.com
Push Port: <port(5 chars)>
As you can see, the App id has two parts. The prefix before the dash is your CPID, and the rest is the id. Then we have an URL where we will need to replace the XXX with the CPID (note that the CPID usually is a 4 digit number, so it would have been better if they had used XXXX as placeholder). Finally the port number which has up to 5 digits.
With those params, in your BB app, you would code something like this:
String id = "<your full app id here>";
String url = "http://cp<CPID>.pushapi.eval.blackberry.com"; //Make sure it is http and not https, and check you have replaced <CPID> with the appid prefix.
int port = <port>;
byte serverType = <PushApplicationDescriptor.SERVER_TYPE_BPAS or
PushApplicationDescriptor.SERVER_TYPE_NONE>;
ApplicationDescriptor descriptor = ApplicationDescriptor.currentApplicationDescriptor();
PushApplicationDescriptor pushDescriptor = new PushApplicationDescriptor(id, port, url, serverType, descriptor);
// This is how we would register the client app:
PushApplicationRegistry.registerApplication(pushDescriptor);
After executing that line, if everything is ok (registration needs some time, a few connections are made), you can check the registration status calling PushApplicationRegistry.getStatus or via the onStatusChange callback.

Resources