I've been asked if I can read the weight from a scale, connected via RS232, and dump it into a web application. Reading the weight of the scale from the local machine isn't bad (this SO question gives an explanation: RS232 question - how to read weight to PC), but...
How do I then get that data to paste into a box in my web application...? Ideas?
I'm running into a similar-but-reverse situation with Fedex and UPS labels. I can get the label data within the web application, but I need to send that data via a raw printer socket (i.e. I can't just File > Print) to the local printer... how?
FedEx and UPS now how Zebra printers that can be network attached. Printing to them is easy via .NET and the standard Windows Spooler using the UNC path to the printer. The trick is how to expose the printer to your web application. If you web application is on the same network as your printer (intranet), the answer is simple. Send the data to the printer via the Windows Spooler from your web server in a server side call from your web app clients. If your web application is hosted outside of your local network, stand up a web service and write a web service to receive the ZPL (Zebra Printer Language) from your web app. The web service would also use the windows spooler to send to the printer on the same network.
Usually web applications are unable to communicate directly with a PC unless there's a full trust between the server and the client. Even then, web pages lack the ability to talk to peripheral devices for myriad security reasons. For a problem like this, you'd almost have to run some kind of client/service background application on the PC.
For the print from web app functionality, QZ Tray is a little java app that does the heavy lifting for you. You can snakeoil a cert, too, instead of paying for their custom cert for their silent printing.
I've been asked if I can read the weight from a scale, connected via RS232, and dump it into a web application.
Although this can't be done directly through JavaScript, a custom client-side or server-side solution can help. There are some server-side and desktop products which expose this functionality to a webpage (RS232 scales, USB scales)
To elaborate specifically on Gordon's recommended QZ Tray approach (assumes the PC has QZ Tray installed; assumes the page has been configured to use QZ Tray), here's a technique which will work for a serial port connected to a Mettler Toledo scale. The commands vary between scale suppliers, so adapt as needed.
Disclaimer, we're the authors of QZ Tray.
Connect to COM1, send command, disconnect
// MT = Mettler Toledo. Change as needed.
var port = 'COM1'; // <-- COM1, '/dev/ttyUSB0', etc
var cmd = 'W\n'; // <--- MT Weight command
var baud = {
baudRate: 9600,
dataBits: 7, // <--- MT Changed from 8
stopBits: 1,
parity: 'EVEN', // <--- MT Changed from NONE
flowControl: 'NONE'
};
var delims = {
begin: '\x02', // <--- MT start of message
end: '\x0D', // <--- MT end of message
width: null // <--- MT doesn't use width
};
qz.serial.openPort(port, delims).then(function() {
return qz.serial.sendData(port, cmd, baud);
}).catch(function(err) { console.error(err); } );
qz.serial.setSerialCallbacks(function(evt) {
if (evt.type !== 'ERROR') {
console.log('Serial', evt.portName, 'received output', evt.output);
} else {
console.error(evt.exception);
}
// Close port
return qz.serial.closePort(evt.portName);
});
I'm running into a similar-but-reverse situation with Fedex and UPS labels. I can get the label data within the web application, but I need to send that data via a raw printer socket (i.e. I can't just File > Print) to the local printer... how?
Duplicate of https://stackoverflow.com/a/28783269/3196753.
Related
we are trying to set some telemetry environment on a Juniper VMX (virtual) router located on AWS.
We configured the router following the documentation, and tried to get some telemetry data from it via jtimon and Telegraf.
The gRPC connection is established and we do receive data, but not exactly what we want. Before continuing, I'm sharing the configuration that we use :
Router configuration (telemetry-related) :
system {
services {
extension-service {
request-response {
grpc {
clear-text {
port 32767;}
skip-authentication;
}
}
notification {
allow-clients {
address 0.0.0.0/0;
}
}
}
}
schema {
openconfig {
unhide;}
On Telegraf, we have these settings (for example) :
[[inputs.jti_openconfig_telemetry]]
servers = ["10.0.100.202:32767"]
sample_frequency = "10000ms"
sensors = [
"15000ms /junos/system/linecard/cpu/memory"
"2000ms /components"
]
collection_jitter = "0s"
flush_interval = "15s"
flush_jitter = "0s"
precision = ""
debug = true
quiet = false
Basically, our sensors gets created on the router, and we can see them with the show agent sensors command. What we cannot understand is that if we change the sensor in the configuration file of Telegraf, we will still receive the information of all previously subscribed sensors. To be clear : in the example, we subscribe to /junos/system/linecard/cpu/memory and /components. If I delete these lines, subscribe to /interfaces and run Telegraf, we will receive the information from the 3 sensors (/components, .../cpu/memory and /interfaces).
As we understand, this is due to an "ephemeral-configuration" called "junos-analytics", as written in the official documentation :
Starting in Junos OS Release 18.2R1, when an external streaming server, or collector, provisions sensors to export data through gRPC on devices running Junos OS, the sensor configuration is committed to the junos-analytics instance of the ephemeral configuration database, and the configuration can be viewed by using the show ephemeral-configuration instance junos-analytics operational command.
Thing is, we don't understand how to edit/disable/delete this "junos-analytics" instance. From what we see, some new sensors (sometimes with the exact same path) get created (with a different sensor ID / name) everytime we run Telegraf. We don't know how to delete them (we tried with a delete services analytics sensor *sensor_name* but it resulted in a "statement not found" error message...).
To sum up, we do receive our sensors' data, but it comes in the middle of lots and lots of other (useless) previously subscribed data.
I feel like we might be missing something in the router configuration, as Telegraf and jtimon show the same behaviour/results.
Any help is appreciated, I can of course share more information if needed ! Thanks in advance :)
Just in case someone is having the same problem : we contacted the Juniper support, they asked us to upgrade our Junos version (from 18.2 to 19.X) and that solves the problem !
To start off, I'd like to state that this is my first dive into Asterisk related applications, and that I'm mostly a web developer.
My workplace uses an MSP that installed Asterisk/FreePBX to manage our phone systems. The GUI is pretty intuitive and after reading and getting a bit lost I figured I'd come here and see how to go about setting this up.
I was tasked with building a simple application to reset user passwords through both a web interface (completed) and a phone interface - by dialing a number, dialing their ID card #, and then having their password reset. I'm a Systems Administrator and have access to all necessary applications, servers, etc. I can pick things up fairly easy and I was told I'd have enough time to figure this out and get it done.
This is what I need in terms of pseudocode when the user calls a specific extension:
recording('pwResetCardID'); // Play a "Please enter your ID # to reset PW" greeting.
function getCardID() {
cardID = input(); // Input 4-5 digits using the dialpad and save it to a var.
verify = get('http://some.site/endpoint/cardid/'.$cardid); // Send a GET request.
if verify { // If we got a successful response (200)
recording('pwChanged'); // Tell the user their password has changed
} else { //
recording('errorCardID'); // Otherwise tell them to try again
getCardID(); // Recur the function.
}
}
getCardID();
If the cardID is valid, their PW is changed on the other end of my node.js application, and I simply need the GET request to be sent out and the user notified of the success (or failure)
You can start from doc describing asterisk dialplan
Probably need use func_CURL, Read application, Playbavk and Goto
You need put new dialplan in extensions_custom.conf and setup use it via custom apps module
I am trying to create a QT based application that scan and connect WiFi networks. I am using this example as a reference code.
Is it possible to assign static IP for the WiFi connection using QNetworkConfiguration or any related class ?
How to authenticate the networks that are password protected ?
thanks in advance......
I have created a net work session using the below code set..
void BearerMonitor::createNewSessionFromQml(QString ssid)
{
QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations();
while (!allConfigurations.isEmpty()) {
QNetworkConfiguration config = allConfigurations.takeFirst();
if(config.name()==ssid)
createSessionFor(config);
}
}
SessionWidget::SessionWidget(const QNetworkConfiguration &config, QObject *parent):QObject(parent)
{
session = new QNetworkSession(config, this);
session->open();
}
No you can't. At least not with just Qt APIs.
Please read this and in particular this. QNetworkConfiguration is just a facility to manage network configurations. Editing such configurations is demanded to native code / OS interactions. From the second link:
Note that the QNetworkConfiguration object only provides limited information about the configuration details themselves. It's main purpose is to act as a configuration identifier through which link layer connections can be created, destroyed and monitored.
Even the "start/stop network interfaces" claim is not entirely true since such a feature is available only in certain OSs (not the mobile ones). See the "Platform capabilities" section of the second link for more details about that.
The same reasoning applies to the password question. Once a network is registed in the OS with the corresponding password (because of native code or the user physically registering it) a new configuration is available to the NetworkConfigurationManager, granted that the list of configurations is updated via updateConfigurations(). The new configuration contains the password but you can't edit it from Qt APIs.
Native code is the only solution, as said. Still, Apple does not want you to mess up with WiFi programatically since private APIs for that cannot be used in iOS > 5.1 (the oldest version supported by Qt as for Qt 5.4).
I'm working on an Adobe AIR application which can upload files to a web server, which is running Apache and PHP. Several files can be uploaded at the same time and the application also calls the web server for various API requests.
The problem I'm having is that if I start two file uploads, while they are in progress any other HTTP requests will time out, which is causing a problem for the application and from a user point of view.
Are Adobe AIR applications limited to 2 HTTP connections, or is something else probably the issue?
From searching about this issue I've not found much but one article did indicated that it wasn't limited to just two connections.
The file uploads are performed by calling the File classes upload method, and the API calls are done using the HTTPService class. The development web server I am using is a WAMP server, however when the application is released it will be talking to a LAMP server.
Thanks,
Grant
Here is the code I'm using to upload the file:
protected function btnAddFile_clickHandler(event:MouseEvent):void
{
// Create a new File object and display the browse file dialog
var uploadFile:File = new File();
uploadFile.browseForOpen("Select File to Upload");
uploadFile.addEventListener(Event.SELECT, uploadFile_SelectedHandler);
}
private function uploadFile_SelectedHandler(event:Event):void
{
// Get the File object which was used to select the file
var uploadFile:File = event.target as File;
uploadFile.addEventListener(ProgressEvent.PROGRESS, file_progressHandler);
uploadFile.addEventListener(IOErrorEvent.IO_ERROR, file_ioErrorHandler);
uploadFile.addEventListener(Event.COMPLETE, file_completeHandler);
// Create the request URL based on the download URL
var requestURL:URLRequest = new URLRequest(AppEnvironment.instance.serverHostname + "upload.php");
requestURL.method = URLRequestMethod.POST;
// Set the post parameters
var params:URLVariables = new URLVariables();
params.name = "filename.ext";
requestURL.data = params;
// Start uploading the file to the server
uploadFile.upload(requestURL, "file");
}
Here is the code for the API calls:
private function sendHTTPPost(apiFile:String, postParams:Object, resultCallback:Function, initialCallerResultCallback:Function):void
{
var httpService:mx.rpc.http.HTTPService = new mx.rpc.http.HTTPService();
httpService.url = AppEnvironment.instance.serverHostname + apiFile;
httpService.method = "POST";
httpService.requestTimeout = 10;
httpService.resultFormat = HTTPService.RESULT_FORMAT_TEXT;
httpService.addEventListener("result", resultCallback);
httpService.addEventListener("fault", httpFault);
var token:AsyncToken = httpService.send(postParams);
// Add the initial caller's result callback function to the token
token.initialCallerResultCallback = initialCallerResultCallback;
}
If you are on a windows system, Adobe AIR is using Microsofts WinINet library to access the web. This library by default limits the number of concurrent connections to a single server to 2:
WinInet limits the number of simultaneous connections that it makes to a single HTTP server. If you exceed this limit, the requests block until one of the current connections has completed. This is by design and is in agreement with the HTTP specification and industry standards.
... Connections to a single HTTP 1.1 server are limited to two simultaneous connections
There is an API to change the value of this limit but I don't know if it is accessible from AIR.
Since this limit also affects page loading speed for web sites, some sites are using multiple DNS names for artifacts such as images, javascripts and stylesheets to allow a browser to open more parallel connections.
So if you are controlling the server part, a workaround could be to create DNS aliases like www.example.com for uploads and api.example.com for API requests.
So as I was looking into this, I came across this info about using File.upload() in the documentation:
Starts the upload of the file to a remote server. Although Flash Player has no restriction on the size of files you can upload or download, the player officially supports uploads or downloads of up to 100 MB. You must call the FileReference.browse() or FileReferenceList.browse() method before you call this method.
Listeners receive events to indicate the progress, success, or failure of the upload. Although you can use the FileReferenceList object to let users select multiple files for upload, you must upload the files one by one; to do so, iterate through the FileReferenceList.fileList array of FileReference objects.
The FileReference.upload() and FileReference.download() functions are
nonblocking. These functions return after they are called, before the
file transmission is complete. In addition, if the FileReference
object goes out of scope, any upload or download that is not yet
completed on that object is canceled upon leaving the scope. Be sure
that your FileReference object remains in scope for as long as the
upload or download is expected to continue.
I wonder if something there could be giving you issues with uploading multiple files. I see that you are using browserForOpen() instead of browse(). It seems like the probably do the same thing... but maybe not.
I also saw this in the File class documentation
Note that because of new functionality added to the Flash Player, when publishing to Flash Player 10, you can have only one of the following operations active at one time: FileReference.browse(), FileReference.upload(), FileReference.download(), FileReference.load(), FileReference.save(). Otherwise, Flash Player throws a runtime error (code 2174). Use FileReference.cancel() to stop an operation in progress. This restriction applies only to Flash Player 10. Previous versions of Flash Player are unaffected by this restriction on simultaneous multiple operations.
When you say that you let users upload multiple files, do you mean subsequent calls to browse() and upload() or do you mean one call that includes multiple files? It seems that if you are trying to do multiple separate calls that that may be an issue.
Anyway, I don't know if this is much help. It definitely seems that what you are trying to do should be possible. I can only guess that what is going wrong is perhaps a problem with implementation. Good luck :)
Reference: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#upload()
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#browse()
Just because I was thinking about a very similar question because of an error in one of my actual apps, I decided to write down the answer I found.
I instantiated 11
HttpConnections
and was wondering why my Flex 4 Application stopped working and threw an HTTP-Error although it was working pretty good formerly with just 5 simultanious HttpConnections to the same server.
I tested this myself because I did not find anything regarding this in the Flex docs or on the internet.
I found that using more than 5 HTTPConnections was the reason for the Flex application to throw the runtime error.
I decided to instantiate the connections one after another as a temporally workaround: Load the next one after the other has received the data and so on.
Thats of course just temporally since one of the next steps will be to alter the responding server code in that way that it answers a request that contains the results of requests to more then one table in one respond. Of course the client application logic needs to be altered, too.
I'm creating a Qt Symbian application and need to connect to internet. In some way I need to let the user choose a connection ONCE when the app starts or use the DEFAULT connection if that is enabled.
Before I just used qt_SetDefaultIap() to set the connection on start. It worked perfect but now I need to use QtMobility instead. I have tried the following in QMainWindow when my app starts:
QNetworkConfigurationManager manager;
const bool selectIap = (manager.capabilities()& QNetworkConfigurationManager::CanStartAndStopInterfaces);
QNetworkConfiguration defaultIap = manager.defaultConfiguration();
if(!defaultIap.isValid() && (!selectIap && defaultIap.state() != QNetworkConfiguration::Active))
{
// let the user know that there is no access point available
}
session = new QNetworkSession(defaultIap,this);
session->open();
But there must be something I'm missing as the application always asks the user to choose connection each time it uses internet not just once as I want. And even if I choose a connection the application asks three times. EDIT: It works on Nokia 5800 but not on N97.
This seems to be a problem for many people as it has been discussed before:
http://discussion.forum.nokia.com/forum/showthread.php?196396-how-to-use-QNetworkConfigurationManager-to-handle-access-point
http://discussion.forum.nokia.com/forum/showthread.php?199401-How-to-use-bearer-management-to-select-access-point
http://discussion.forum.nokia.com/forum/showthread.php?199472-How-can-I-set-the-best-one-access-point-as-default
Any ideas on how to get this working?
if your phone settings are set as 'Always ask' in (5800) Menu -> Settings -> Destinations -> Options -> Default connection, then QNetworkConfigurationManager.defaultConfiguration() will return the UserChoice configuration, which will always popup a query.
If you wish to control which access point is really used, then you could enumerate/list the configurations (QNetworkConfigurationManager::allConfigurations(), choose the one you want, and then create a QNetworkSession based on it and call QNetworkSession::open(). After that if you instantiate and use e.g. QNetworkAccessManager to perform web queries, they should use that configuration "automatically".