SPP-CA OperationError occurred - c++

I am writing / hacking QT C++ Bluetooth example code and I am hesitant to make more specific references to the code. The code is buggy and uncommented...so let me leave it at that.
I have is basically working - all the way to setting up a socket.
I expect socket "connected " event, but instead of that I am getting the
"SPP-CA OperationError occurred".
Here is the code producing the error
// Connect to service
socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
qDebug() << "Create socket";
text = socket->errorString();
if(socket->errorString().isEmpty())
{
text += " NO socket Error Occurred \n ";
qDebug()<<text;
}
else
{
text += " FAILED to create socket ";
qDebug()<<text;
}
// verify remoteService
if(remoteService.isComplete() & remoteService.isValid())
{
text = "remoteService.isComplete() & remoteService.isValid()";
qDebug()<<text; }
else
{
text = "!!!!!!!!!!!!!!!!!!! FAILED remoteService.isComplete()";
qDebug()<<text;
}
socket->connectToService(remoteService);
// check ChatClient::connected)
// czech onSocketErrorOccurred
None of my socket verification code is resulting in "FAILED" - it all passes.
I am assuming the error is actually coming from the Bluetooth SPP_CA adapter AFTER I send plain ASCII text to it.
The SPP_CA is attached to a device which expect specific RS232 format - baud rate etc.
Here is my basic question - according to few "opinions" - Bluetooth "RFCOMM" protocol
DOES NOT require RS232 to be configured - it "does it automatically ".
True or false ?
With that - what / who is generating this error and why I do not see "connect" event first?
PS I could post the "connect" macros if necessary.

Related

Discord.js v12 Bot Say Command in different channel (via args?)

Im looking for some help/direction/suggestion... I have my discord bot say command here, its taken me a while to get it this far and working. What im looking for is to adapt the current code so that i can check if the word after ".say" is a "#channel" and if so send the message there. ie ".say #feedback your welcome" ....... would result in the bot saying "your welcome" in the feedback channel ELSE just send the message within the same channel. I hope i have explained myself properly but this is over my head, iv tried to research as much as possible. thanks in advance for your time
case 'say':
if (!message.member.roles.cache.find(r => r.name === 'Moderator') && !message.member.roles.cache.find(r => r.name === 'Staff')) return message.channel.send('You dont not have the required permissions').then(msg => {
msg.delete({ timeout: 5000 })
})
else if (message.content.startsWith(".say")) {
if (message.deletable) {
message.delete();
}
if (!args[1]) return message.channel.send("Nothing to say").then(msg => {
msg.delete({ timeout: 5000 })
})
message.channel.send(`${(args.slice(1).join(" "))}`)
To check if a channel is mention in the incoming message, you can use Message.mentions property that returns a MessageMentions object.
MessageMentions.channels returns a Collection of GuildChannel that are mention in the message.
So to check if at least one channel is mention in the message :
if (message.mentions.channels.size > 0) {
// There is at least 1 channel mention in the message.
} else {
// No channel mention in the message.
}
To send a message to the first channel mention :
message.mentions.channels.first().send("message");

String Class Weird Behavior

I'm new to Arduino and C++, and I'm working on an Arduino project for school. I have a Firebase Cloud Function and I want to call if from the Arduino. I start a connection with the server and give it a query:
const String query = "QUERY";
if (client.connect(server, 80)) {
Serial.print("Connected to ");
Serial.println(client.remoteIP());
// Make an HTTP request:
client.println(query);
client.println("Host: SERVER-HOST-NAME");
client.println("Connection: close");
client.println();
}
Now this works very fine if the query string was declared as one piece:
String query = String("GET /cloudFunctionName?dataThatShouldBeVariable=FixedData HTTP/1.1");
Example:
String query = String("GET /updateDatabase?temp=10 HTTP/1.1");
When using the method above the cloud function triggers and the database gets updated. But I can't use it in production because I have some variable data so what I did was:
String query = String("GET /cloudFunctionName?dataThatShouldBeVariable=" + String(VariableData) + " HTTP/1.1");
Example:
String query = String("GET /updateDatabase?temp=" + String(10) + " HTTP/1.1");
Now when I print the results of the two strings I get the same result, but when using the second method the cloud function doesn't get triggered and the database doesn't get updated.
I believe that the problem is with the query variable not with the server or the hardware but I couldn't find an answer. I've been working on this for hours and I really got mad and I don't know what to do. Please tell me what is the problem and how to fix it.

Pepper robot: How to use tablet to send text input for further processing in Choregraphe?

I need to send a user text input to the robot through the integrated tablet, and catch it somehow, for further processing in Choregraphe.
After reading the Aldebaran documentation about ALTabletService API, I found few methods which might be a solution to all this. The methods are ALTabletService::showInputTextDialog and ALTabletService::onInputText, but somehow I can't get them to work: they return absolutely nothing when I input some text through the tablet.
I need access to the string created when the user inputs a piece of text. Any advice how to do it?
i realized this without ALTabletService methods showInputTextDialog or onInputText
My Approach:
I made an html page with an input field and a button to send the input.
On button press I use the forceInput method from ALDialog doc via QiMessaging Javascript library. doc
I can't test it right now but this should help as a inspiration
function forceInput(input) {
QiSession(function(session) {
session.service('ALDialog').then(function(ALDialog) {
ALDialog.forceInput(input);
});
}
}
Now you can send the input to the topic.
This could be sth like "imput_from_tablet blablabla".
And in the Dialog you catch
u:(imput_from_tablet _*) $1
Where $1 should be blablabla.
Hope that helps
best regards
You can create a webpage for the tablet and package it in your application - see the documentation here; then on that webpage you can create a text input field (be careful that the bottom half of the screen will be hidden by the keyboard when the field is selected), and then use the javascript SDK to (for example) raise an ALMemory event with the inputted text value, that you can then get from Choregraphe.
I had exactly the same problem and I found this ALTabletService::onInputText method in the signal list. You can find examples how to use signals on the same page. Based on these examples I created the following script that can get a value from the input field:
import qi
import sys
def main(app):
try:
session = app.session
tabletService = session.service("ALTabletService")
tabletService.showInputTextDialog("Example dialog", "OK", "Cancel")
signal_id = 0
def callback(button_id, input_text):
if button_id == 1:
print "'OK' button is pressed."
print "Input text: " + input_text
if button_id == 0:
print "'Cancel' button is pressed"
tabletService.onInputText.disconnect(signal_id)
app.stop()
# attach the callback function to onJSEvent signal
signal_id = tabletService.onInputText.connect(callback)
print "Signal ID: {}".format(signal_id)
app.run()
except Exception, e:
print "Error was: ", e
if __name__ == "__main__":
ip = "10.0.10.254" # the IP of the robot
port = 9559
try:
connection_url = "tcp://{}:{}".format(ip, port)
app = qi.Application(url=connection_url)
app.start()
except RuntimeError:
print("Can't connect to Naoqi.")
sys.exit(1)
main(app)

Is it possible for an SFDC Apex unit test to parse a debug log?

I'm currently playing around with SFDC-Http Integration and the new Mock server functionality.
In the Apex code which I am testing, I have this branch condition:
if (response.getStatusCode() != 200) { debugResponse (response); }
else { update (processInvoiceList(invoiceIdList, response)); }
... and I can thoroughly test what happens if the status code is 200.
However, if the status code is not 200, the code executed is simply this:
/**
* Write debugging information
* #param HttpResponse response : Http response (e.g., from sendJsonToRemoteService())
* #return None
**/
private static void debugResponse (HttpResponse response)
{
System.debug(
LoggingLevel.ERROR ,
'!!!!! Error from ' + request.getEndpoint() + ' : ' + response.getStatusCode() + ' ' + response.getStatus()
);
}
This being the case, as the code currently stands, the only changes made to the system to check for would be to check the debug log.
I realize I could refactor my source to expose the HttpResponse (i.e. make it a public class variable), but aside from testing there is no need to expose it, so I don't want to if I don't need to.
So, instead, I'd like my unit test to parse the error log for the error message.
Is this possible?
If so, how?

What is wrong with my redirect machanism?

So I try to create a C++ web server with services and stuff. It is alive here, this is how to compile in in 3 lines under regular user on Linux, and here is it svn.
To redirect users I use such function:
void http_utils::send_found_302( std::string redirect_lication, boost::shared_ptr<boost::asio::ip::tcp::socket> socket, boost::shared_ptr<http_response> response )
{
response->status = 302;
response->description = "Found";
response->headers.insert(std::pair<std::string, std::string>("Location", redirect_lication));
response->send(*socket);
}
And in Chrome and Safary and IE. I can register and log in into my server. But FF... FF allows me to registe user in DB (meaning sends correct request), but when server trys to redirect it to page I want it shows me sad page=(
So example with pictures: we input credantials:
We hit on submit... and is gets stuck on connection for ever...:
When we try just to use that URL it tries to go to we see that it got part of "Found response" but has not redirected itself...( If we would try to login with chrome we would get all correct, also if we would just follow that url in chrome we would get redirected to where needed and see such image:
I created a simple user: demo_user#gmail.com with pass 123456 so you can try it out...
So what is wrong with the way I redirect? what shall be added to response to make it work for FF?
At the end of the day I made this:
void http_utils::send_found_302( const std::string & redirect_lication, boost::shared_ptr<boost::asio::ip::tcp::socket> socket, boost::shared_ptr<http_response> response )
{
/* if there was no Fire Fox and probably other dull browsers we would do this (Chrome, IE, Safari tested):
*
*\code
response->status = 302;
response->description = "Found";
response->headers.insert(std::pair<std::string, std::string>("Location", redirect_lication));
response->send(*socket);
* \endcode
*
* but indeed there are.
*
* We could also create simple HTML redirection page - would work anywhere.
* \code
std::ostringstream data_stream;
data_stream << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><script type=\"text/javascript\">location.replace(\""
<< redirect_lication << "\");</script><noscript><meta http-equiv=\"refresh\" content=\"0; url= "
<< redirect_lication << "\"></noscript></head><body><p>Please turn on JavaScript!</p><a href=\""
<< redirect_lication << "\"><h1>Content awaits you here.</h1></a></body></html>";
response->headers.insert(std::pair<std::string, std::string>("Cache-Control", "max-age=0"));
response->headers.insert(std::pair<std::string, std::string>("Pragma", "no-cache"));
http_utils::send(data_stream.str(), socket, response);
* \endcode
*
* so we decided to mix - html page and HTTP redirection
*/
response->description = "Found";
response->headers.insert(std::pair<std::string, std::string>("Location", redirect_lication));
response->headers.insert(std::pair<std::string, std::string>("Content-Location", redirect_lication));
response->headers.insert(std::pair<std::string, std::string>("Refresh", std::string("0; url=" + redirect_lication)));
response->headers.insert(std::pair<std::string, std::string>("Cache-Control", "max-age=0"));
response->headers.insert(std::pair<std::string, std::string>("Pragma", "no-cache"));
std::ostringstream data_stream;
data_stream << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><script type=\"text/javascript\">location.replace(\""
<< redirect_lication << "\");</script><noscript><meta http-equiv=\"refresh\" content=\"0; url= "
<< redirect_lication << "\"></noscript></head><body><p>Please turn on JavaScript!</p><a href=\""
<< redirect_lication << "\"><h1>Content awaits you here.</h1></a></body></html>";
http_utils::send(302, data_stream.str(), socket, response);
}
Let me explain: Current FF did not like my 302 and 303 redirection... so Simple solution - was to move the battle to the other side - side of HTML so I created simple code that returns HTML page that would auto redirect user or at least present him with correct link. Tested it - all worked as was desired (with short local links). Than I added solution that also worked not only I send HTML page but, also relocation headers. This shall work anywhere, and if browser is smart it shall not load contents of redirection page at all...)
So now all works.=) And thanks to KayEss answer I made all links absolute now... Why not?)
For best portability the location header needs to be an absolute URL. It looks like you're trying to send a relative one.
I.e.:
Location: http://example.com/path/image.png
Instead of:
Location: image.png