I need to send a string from the arduino to the web form on that page https://vibrant-bastille-64033.herokuapp.com/ and submits the form.
This is the current code of my arduino, what is wrong, or what is missing..
void SubmitHttpRequest()
{
mySerial.println("AT+CSQ");
delay(100);
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
mySerial.println("AT+CGATT?");
delay(100);
ShowSerialData();
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(5000);
ShowSerialData();
mySerial.println("AT+SAPBR=3,1,\"APN\",\"internet.vodafone.net \"");//setting the APN, the second need you fill in your local apn server
delay(8000);
ShowSerialData();
mySerial.println("AT+SAPBR=0,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(5000);
ShowSerialData();
mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(8000);
ShowSerialData();
mySerial.println("AT+HTTPTERM"); //term the HTTP request
delay(5000);
mySerial.println("AT+HTTPINIT"); //init the HTTP request
delay(5000);
ShowSerialData();
mySerial.println("AT+HTTPPARA=\"URL\",\"vibrant-bastille-64033.herokuapp.com/create\"");// setting the httppara, the second parameter is the website you want to access
delay(5000);
ShowSerialData();
mySerial.println("AT+HTTPDATA=1000,10000"); //100 refers to how many bytes you're sending. You'll probably have to tweak or just put a large #
delay(10000);
ShowSerialData();
mySerial.println("[\"id\": \"01\",\"current_value\": \"" "\",");
delay(500);
mySerial.println("TEST from Arduino"); //ie latitude,longitude,etc...
delay(5000);
ShowSerialData();
mySerial.println("AT+HTTPACTION=1");//submit the request
delay(5000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
while(!mySerial.available());
ShowSerialData();
mySerial.println("finish");
delay(100);
mySerial.println("[\"id\": \"01\",\"current_value\": \"" "\",");
delay(500);
ShowSerialData();
}
Related
I have developed an application for streaming speech recognition in c++ using another API and IBM Watson Speech to Text service API.
In both these programs, I am using the same file which contains this audio
several tornadoes touch down as a line of severe thunderstorms swept through Colorado on Sunday
This file is 641,680 bytes in size and I am sending 100,000 bytes (max) chunks at a time to the Speech to text servers.
Now, with the other API I am able to have everything recognized as a whole. With the IBM Watson API I couldn't. Here is what I have done:
Connect to IBM Watson web server (Speech to text API)
Send start frame {"action":"start","content-type":"audio/mulaw;rate=8000"}
Send binary 100,000 bytes
Send stop frame {"action":"stop"}
...Repeat binary and stop until the last byte.
The IBM Watson Speech API could only recognize the chunks individually
e.g.
several tornadoes touch down
a line of severe thunder
swept through Colorado
Sunday
This seems to be the output of individual chunks and the words coming in between the chunk division (for eg here, "thunderstorm" is partially present in the end of a chunk and partially in the starting of the next chunk) are thus incorrectly recognized or dropped.
What am I doing wrong?
EDIT (I am using c++ with boost library for websocket interface)
//Do the websocket handshake
void IbmWebsocketSession::on_ssl_handshake(beast::error_code ec) {
auto mToken = mSttServiceObject->GetToken(); // Get the authentication token
//Complete the websocket handshake and call back the "send_start" function
mWebSocket.async_handshake_ex(mHost, mUrlEndpoint, [mToken](request_type& reqHead) {reqHead.insert(http::field::authorization,mToken);},
bind(&IbmWebsocketSession::send_start, shared_from_this(), placeholders::_1));
}
//Sent the start frame
void IbmWebsocketSession::send_start(beast::error_code ec) {
//Send the START_FRAME and call back the "read_resp" function to receive the "state: listening" message
mWebSocket.async_write(net::buffer(START_FRAME),
bind(&IbmWebsocketSession::read_resp, shared_from_this(), placeholders::_1, placeholders::_2));
}
//Sent the binary data
void IbmWebsocketSession::send_binary(beast::error_code ec) {
streamsize bytes_read = mFilestream.rdbuf()->sgetn(&chunk[0], chunk.size()); //gets the binary data chunks from a file (which is being written at run time
// Send binary data
if (bytes_read > mcMinsize) { //Minimum size defined by IBM is 100 bytes.
// If chunk size is greater than 100 bytes, then send the data and then callback "send_stop" function
mWebSocket.binary(true);
/**********************************************************************
* Wait a second before writing the next chunk.
**********************************************************************/
this_thread::sleep_for(chrono::seconds(1));
mWebSocket.async_write(net::buffer(&chunk[0], bytes_read),
bind(&IbmWebsocketSession::send_stop, shared_from_this(), placeholders::_1));
} else { //If chunk size is less than 100 bytes, then DO NOT send the data only call "send_stop" function
shared_from_this()->send_stop(ec);
}
}
void IbmWebsocketSession::send_stop(beast::error_code ec) {
mWebSocket.binary(false);
/*****************************************************************
* Send the Stop message
*****************************************************************/
mWebSocket.async_write(net::buffer(mTextStop),
bind(&IbmWebsocketSession::read_resp, shared_from_this(), placeholders::_1, placeholders::_2));
}
void IbmWebsocketSession::read_resp(beast::error_code ec, size_t bytes_transferred) {
boost::ignore_unused(bytes_transferred);
if(mWebSocket.is_open())
{
// Read the websocket response and call back the "display_buffer" function
mWebSocket.async_read(mBuffer, bind(&IbmWebsocketSession::display_buffer, shared_from_this(),placeholders::_1));
}
else
cerr << "Error: " << e->what() << endl;
}
void IbmWebsocketSession::display_buffer(beast::error_code ec) {
/*****************************************************************
* Get the buffer into stringstream
*****************************************************************/
msWebsocketResponse << beast::buffers(mBuffer.data());
mResponseTranscriptIBM = ParseTranscript(); //Parse the response transcript
mBuffer.consume(mBuffer.size()); //Clear the websocket buffer
if ("Listening" == mResponseTranscriptIBM && true != mSttServiceObject->IsGstFileWriteDone()) { // IsGstFileWriteDone -> checks if the user has stopped speaking
shared_from_this()->send_binary(ec);
} else {
shared_from_this()->close_websocket(ec, 0);
}
}
IBM Watson Speech to Text has several APIs to transmit audio and receive transcribed text. Based on your description you seem to use the WebSocket Interface.
For the WebSocket Interface, you would open the connection (start), then send individual chunks of data, and - once everything has been transmitted - stop the recognition request.
You have not shared code, but it seems you are starting and stopping a request for each chunk. Only stop after the last chunk.
I would recommend to take a look at the API doc which contains samples in different languages. The Node.js sample shows how to register for events. There are also examples on GitHub like this WebSocket API with Python. And here is another one that shows the chunking.
#data_henrik is correct, the flow is wrong, it should be: ...START FRAME >> binary data >> binary data >> binary data >> ... >> STOP FRAME
you only need to send the {"action":"stop"} message when there are no more audio chunks to send
I am trying to send over 20 bytes in ionic ble native without success,
first of all I send without response and then this response but still not working
how I do this?
var newSend=this.myInput.match(/.{1,19}/g);
console.log(newSend);
for(var i = 0 ; i<newSend.length ; i++){
var ddd = newSend[i].buffer;
this.sendingtext=newSend[i];
console.log(i,newSend.length);
if(i == (newSend.length-1)){
this.ble.write(bID, bService, bCharacteristic, ddd).then(
function(data){
// console.log( this.myInput);
console.log("write",data);
}
);
}else{
this.ble.writeWithoutResponse(bID, bService, bCharacteristic, ddd).then(
function(data){
// console.log( this.myInput);
console.log("writeWithoutResponse",data);
}
);
}
That is not acceptable. BLE is low energy bluetooth, so it's protocol limit the packet size of a command. In general the maximum payload size you can send over BLE write is 20 bytes
Follow this link to read more about how to send larger 20 bytes over BLE
Android: Sending data >20 bytes by BLE
It's a misconception that Write Without Response doesn't give a response; it does.
You just don't have to wait for response.
It is meant to decrease the time between successive packets,
we can send and receive data between a client and server without waiting for a response after each message.
There are some restrictions:
You have to comply with the MTU of the server.
The receive buffer of the server must be large enough to hold the incoming packets.
There must be enough time for the server to empty the receive buffer.
Can somebody help me?
I have problems sending data from a SIM800C to a website.
The first problem is, I uploaded the following code to Arduino (I use the Serial Monitor in Arduino IDE to send AT commands to the SIM800 and read the response).
#include <SoftwareSerial.h>
#define TX 10
#define RX 11
#define t 2000
SoftwareSerial mySerial(RX, TX);
int k=0, aS=0, amS=0;
void setup() {
Serial.begin(9600);
while(!Serial); // Wait for Serial ready
Serial.println("Intalizing...");
mySerial.begin(9600);
delay(5000);
mySerial.println("AT"); // Send the first AT command to auto set baud rate
delay(1000);
Serial.println("You can type AT command and send to SIM800 by using Serial Monitor");
}
void loop() {
k=0;
aS=Serial.available(); // aS: The number of bytes available to read from the buff of Serial
amS=mySerial.available(); // amS: The number of bytes available to read from the buff of mySerial
while(aS>0) {
mySerial.write(Serial.read());
k=1; aS--;
}
if (k==1) {
mySerial.println();
}
while (amS>0) {
Serial.write(mySerial.read());
k=2; amS--;
}
delay(1000);
}
Next, I send the AT commands below one by one and viewed responses. All the AT commands and responses can be seen on the Serial Monitor.
AT+SAPBR=3,1,"Contype","GPRS"
AT+SAPBR=3,1,"APN","m3-world"
AT+SAPBR=3,1,"USER","mms"
AT+SAPBR=3,1,"PWD","mms"
AT+CSTT="m3-world","mms","mms"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://weatherstation.byethost3.com/"
AT+HTTPDATA=9,10000
value=YOU
AT+HTTPACTION=1
The last response below shows that the data (value=YOU) have been sent successfully.
OK
++HTTPACTION:1,200,839
I have created a website to read data with the GET method. My problem is nothing changes on the website. That means the website has not read the data sent from the SIM800 yet.
Your example is sending a POST request. If you would like to send a GET request with a name/value pair, it should be structured a little differently. Changing your example from above:
AT+SAPBR=3,1,"CONTYPE","GPRS"
AT+SAPBR=3,1,"APN","m3-world"
AT+SAPBR=3,1,"USER","mms"
AT+SAPBR=3,1,"PWD","mms"
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","http://weatherstation.byethost3.com/?value=YOU"
AT+HTTPACTION=0
Note the name/value pair is in the URL now and AT+HTTPACTION=1 is changed to AT+HTTPACTION=0 to indicate GET instead of POST
I have a problem. When I want to achieve WebSocket server, the server can't send data to the client (in Chrome 16). For example, sending the text "Hello", the server sends the data framing "0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f" to the client, but the browser can't receive the data. Is this code wrong?
sub getSendDataNoMask{
my $dataStr="Hello";
my #ret;
push(#ret,pack("H*","81"));
push(#ret,pack("H*","05"));
push(#ret,$dataStr);
return join("",#ret);
}
What error do you get from the Chrome Javascript console?
You also didn't post your handshake code (the more likely thing to have a problem). Are you certain that the handshake was completed successfully? In other words, did you get an onopen event in the browser?
var ws = WebSocket("ws://myhost:6080/websocket");
ws.onopen = function (e) {
console.log("connection opened");
};
ws.onmessage
console.log("Got data: " + e.data);
};
If you didn't get an opopen event then the handshake never finished successfully. If you are getting on onopen event, then I would try sending data the opposite direction and make sure you can receive and decode frames from your perl server before trying to send.
I asked this question before and had no resolution (still having the problem). I am stumped because the function returned without error and NO DATA was sent! This code works on Linux ... the VxWorks version does not work (sendto does not send, though it returns without an ERROR).
The synopsis - I am writing a simple echo server - The server successfully receives
the data (from an x86 box) and claims it successfully SENT it back.
However NO DATA is received on the client (netcat on an x86). This
code is running on VxWorks 5.4 on a PowerPC box ...
I is the UDP data being buffered somehow?
Could another task be preventing sendto from sending? (NOT to get off on a wild goose chase here, but I taskspawn my application with a normal priority, i.e. below critical tasks like the network task etc etc ... so this is fine).
Could VxWorks be buffering my UDP data?
I HAVE setup my routing table ... pinging works!
There is NO firewall AFAIK ...
What are the nuances of sendto and what would prevent my data from
reaching the client ...
while(1)
{
readlen = recvfrom(sock, buf, BUFLEN, 0, (struct sockaddr *) &client_address, &slen);
if (readlen == ERROR)
{
printf("RECVFROM FAILED()/n");
return (ERROR);
}
printf("Received %d bytes FROM %s:%d\nData: %s\n\n",
readlen, inet_ntoa(client_address.sin_addr),
ntohs(client_address.sin_port), buf);
// Send it to right back to the client using the open UDP socket
// but send it to OUTPORT
client_address.sin_port = htons(OUTPORT);
// Remember slen is a value (not an address ... in, NOT in-out)
sendlen = sendto(sock, buf, BUFLEN, 0, (struct sockaddr*)&client_address, slen);
// more code ....
}
I trust ERROR is defined as -1, right? Then are you checking the return value of the sendto(2) call? What about the errno(3) value?
One obvious problem I see in the code is that you give BUFLEN as length of the message to be sent, while it should actually be readlen - the number of bytes you received.