Azure IoT hub C sdk blob upload example possible without low level API? - azure-iot-hub

I'm trying the iothub_client/samples/iothub_client_sample_upload_to_blob from the Azure IoT hub C sdk. It compiles and works fine if I use the low-level API.
But as soon as I switch to the convenience layer (as the documentation in the app's file suggests), I get an error:
/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_upload_to_blob/iothub_client_sample_upload_to_blob.c: In function ‘iothub_client_sample_upload_to_blob_run’:
/home/user/workspaceMisc/azure-iot-sdk-c/iothub_client/samples/iothub_client_sample_upload_to_blob/iothub_client_sample_upload_to_blob.c:77:25: error: implicit declaration of function ‘IoTHubClient_UploadToBlob’ [-Werror=implicit-function-declaration]
if (IoTHubClient_UploadToBlob(iotHubClientHandle, "subdir/hello_world.txt", (const unsigned char*)HELLO_WORLD, sizeof(HELLO_WORLD) - 1) != IOTHUB_CLIENT_OK)
^
cc1: all warnings being treated as errors
iothub_client/samples/iothub_client_sample_upload_to_blob/CMakeFiles/iothub_client_sample_upload_to_blob.dir/build.make:62: recipe for target 'iothub_client/samples/iothub_client_sample_upload_to_blob/CMakeFiles/iothub_client_sample_upload_to_blob.dir/iothub_client_sample_upload_to_blob.c.o' failed
How can I upload a file with the convenience layer instead of the low level layer? Is it possible at all?
I'm using Ubuntu 16.04, gcc 5.4.0 and the latest clone of the SDK.

Actually the function name is IoTHubClient_UploadToBlobAsync, you need add Async postfix. And there is needed additional two parameters: iotHubClientFileUploadCallback and context. This document is somewhat misleading.
So you can call this function like this:
IoTHubClient_UploadToBlobAsync(iotHubClientHandle, "subdir/hello_world.txt", (const unsigned char*)HELLO_WORLD, sizeof(HELLO_WORLD) - 1, NULL, NULL);

Related

Why am i getting different asset amount using algorand Indexer vs daemon?

So I created a new ASA (AKA: Algorand Standard Asset) and set the total amount of that asset to be maximum.
Here's a quick snippet of how I did it:
const UINT64_MAX: bigint = BigInt('18446744073709551615');
Now, When I check how many tokens asset creator has with Algorand's Daemon API
curl http://localhost:8980/v2/accounts/3IELQKOD...3C5IB3BP4V4A/assets
I get it exactly right as: 18446744073709551615
But when i check it with the indexer in the sdk its something different.
It shows total assets as "18446744073709552000" to be exact which is not true.
What am i doing wrong here or this is error in library?
you need to set your client to support big int or mixed.
as JS Only supports 2^^53
You can easily set it by setting IntDecoding method for all JSON requests created by client here.

Can custom TensorFlow user_ops be served through TensorFlow Serving

I have created custom TensorFlow operators in C++ similar to the examples in tensorflow/user/ops/ and they are working fine when used in TensorFlow sessions.
When saving a SavedModel using the operator, the resulting saved_model does contain the operators (at least a cursory inspection of a text protocol buffer of such a model shows that). Trying to serve this with a tensorflow_model_server of course fails at first, since the operator is unknown.
So I proceeded to extend the tensorflow_model_server with an option to specify the user_ops libraries to be loaded beforehand. The relevant code snippet inserted into "main.cc" of the tensorflow_model_server is:
if (librarypath.size() > 0) {
// Load the library.
TF_Status* status = TF_NewStatus();
TF_LoadLibrary(librarypath.c_str(), status);
if (!TF_GetCode(status) == TF_OK) {
string status_msg(TF_Message(status));
std::cout << "Problem loading user_op library " << librarypath << ": " << TF_Message(status);
return -1; }
TF_DeleteStatus(status);
}
Unfortunately, this does not quite work as expected, I get
Problem loading user_op library /usr/lib64/multipolygon_op.so: /usr/lib64 /multipolygon_op.so: undefined symbol: _ZTIN10tensorflow8OpKernelE
This somehow refers to _pywrap_tensorflow_internal.so symbols. Do I need to build the user op library differently or am I just out of luck ?
Ok, after a trying out a number of different venues the answer turns out to be relatively simple:
The tensorflow_model_server is being linked in such a way that is does not provide its own symbols to newly loaded shared libraries. Thus adding "-rdynamic" to the linker options to change that makes everything fall into place:
bazel build --linkopt=-rdynamic //tensorflow_serving/model_servers:tensorflow_model_server

How to get author of a pdf document with mupdf

how can I get metadata of a pdf document(e.g. title, author, creation date etc) by using mupdf library? There is not enough documentation to find out this functionality. Comments are not sufficient, too. Most probably, there is a functionality for this purpose but it is hard to find under these circumstances. The following code is what I have so far.
char info[64];
globals *glo = get_globals(env, thiz);
fz_meta(glo->doc, FZ_META_INFO, info, sizeof(info));
I have used FZ_META_INFO tag, but it doesn't work. I didn't get any info, just empty. I have checked that it has metadata. Any help is appreciated.
EDIT:
Target Android sdk:20
Min Android sdk:15
Mupdf version: 1.6
ndk: r10c
Development OS: Ubuntu 12.04
In what sense 'doesn't work' ? Throws an error ? Crashes ? Are you certain the PDF file you are using has any 'Info' metadata ?
What is the version of MuPDF ? What platform are you using ?
You need to set the relevant key in the buffer you pass to fz_meta before you call fz_mets, I notice you aren't doing that.
See win_main.c at around line 487, after you get past the macro this resolves to
char info[256]
sprintf(info, "Title");
fz_meta(doc, FZ_META_INFO, info, 256);
On return 'info' will contain the metadata associated with the Title key in the dictionary.
When in doubt, build the sample app and follow it in a debugger......
If the proper casting allow to send the key,
this casting is NOT correct to receive back a char*.
Exemple;
Proper casting to send a request
char buff[2048];
strcpy(buff,"CreationDate")
if (fz_meta(ctx,doc,FZ_META_INFO,&buff,2048)) {
buff[0] = 0;
}
Will:
find the key,
convert utf8
then will crash when copyback of the result
Proper casting to receive a request
char buff[2048];
strcpy(buff,"CreationDate")
if (fz_meta(ctx,doc,FZ_META_INFO,buff,2048)) {
buff[0] = 0;
}
Will crash during dict scanning.
looks really like a bug!
I confirm that modifying original source
info = pdf_dict_gets(ctx, info, (char *)ptr);
is the way to go. (even if strange that nobody else find it while writing code, because Meta are useful features frequently used

Get USB disk drive letter by device path or handle

My goal is to write a c-dll (compiled with MinGW) that is able to search for certain models of USB sticks connected to the computer and deliver the serial number, the vendor ID, the product ID and the drive letter.
I have searched on the internet for several hours know but could not find an approach that works for me.
I am using the Setup Api to get a list of all connected USB devices. For each USB device I get a path that looks like this:
\?\usb#vid_048d&pid_1172#00000020370220#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
From that string I can get the vendor ID, product ID and the serial number I am looking for.
My problem is now to determine the drive letter of the USB drive that is related to this device path.
During my internet research I found the following approach multiple times (for example here http://oroboro.com/usb-serial-number/):
Once the device path is found, the USB drive must be opened by CreateFile. The handle returned by that function can be used to get the device number by function DeviceIOControl with IOCTL_STORAGE_GET_DEVICE_NUMBER.
After that, the CreateFile function could be used to open each drive letter (starting from a:) and try to get the device number the same way like described above. Once the same device number is found again, the relation between device path and drive letter is made.
My Problem is that the IOCTL_STORAGE_GET_DEVICE_NUMBER call is not working. The DeviceIOControl function returns error code 50 which means "The request is not supported".
I am not able to create a link between the device path of a USB stick and the drive letter. I have tried several IOCTL_STORAGE and IOCTL_VOLUME calls but none worked for the USB sticks I tried.
I also read in another Forum that people had problems with the results of the DeviceIOControl function. It was returning the desired result on some PCs while it was making trouble on others.
Is there another way of achieving my goal?
I already had a look into the registry where I can also find the desired data. But again I had the problem to create the connection between device path and drive letter.
I would not like to use the WMI. I have read that it is still not really supported by MinGW.
I have a implementaion for all this with C# where it is really easy to get the desired information, but now I also need one that is created with unmanaged code and can be used to replace a c-dll also included in Delphi projects.
I would appreciate any suggestions for a solution to my problem.
Best regards,
Florian
And here the code if someone is interested. The position with this comment "//HERE IS WHERE I WOULD LIKE TO GET THE DEVICE NUMBER!!!" is where the request of the device number would be used if it would work.
typedef struct ty_TUSB_Device
{
PSP_DEVICE_INTERFACE_DETAIL_DATA deviceDetailData;
char devicePath[300];
}TUSB_Device;
int
GetUSBDevices (TUSB_Device *devList[], int size)
{
HANDLE hHCDev;
HDEVINFO deviceInfo;
SP_DEVICE_INTERFACE_DATA deviceInfoData;
ULONG index;
ULONG requiredLength;
int devCount = 0;
//SP_DEVINFO_DATA DevInfoData;
// Now iterate over host controllers using the new GUID based interface
//
deviceInfo = SetupDiGetClassDevs((LPGUID)&GUID_DEVINTERFACE_USB_DEVICE,
NULL,
NULL,
(DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
if (deviceInfo != INVALID_HANDLE_VALUE)
{
deviceInfoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for (index=0;
SetupDiEnumDeviceInterfaces(deviceInfo,
0,
(LPGUID)&GUID_DEVINTERFACE_USB_DEVICE,
index,
&deviceInfoData);
index++)
{
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&deviceInfoData,
NULL,
0,
&requiredLength,
NULL);
//allocate memory for pointer to TUSB_Device structure
devList[devCount] = malloc(sizeof(TUSB_Device));
devList[devCount]->deviceDetailData = GlobalAlloc(GPTR, requiredLength);
devList[devCount]->deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
SetupDiGetDeviceInterfaceDetail(deviceInfo,
&deviceInfoData,
devList[devCount]->deviceDetailData,
requiredLength,
&requiredLength,
NULL);
//open the usb device
hHCDev = CreateFile(devList[devCount]->deviceDetailData->DevicePath,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
// If the handle is valid, then we've successfully found a usb device
//
if (hHCDev != INVALID_HANDLE_VALUE)
{
strncpy(devList[devCount]->devicePath, devList[devCount]->deviceDetailData->DevicePath, sizeof(devList[devCount]->devicePath));
//HERE IS WHERE I WOULD LIKE TO GET THE DEVICE NUMBER!!!
CloseHandle(hHCDev);
devCount++;
}
//GlobalFree(devList[devCount]->deviceDetailData);
}
SetupDiDestroyDeviceInfoList(deviceInfo);
}
return devCount;
}
I found out what my problem was. From what I read on the internet it seems there where other people having the same problems like me, so I will post my solution.
The whole point is that there are obviously different path values one can obtain for a USB device using the SetupApi. All path values can be used to get a handle to that device, but there are obviously differences about what can be done with the handle.
My failure was to use GUID_DEVINTERFACE_USB_DEVICE to list the devices. I found out that when I use GUID_DEVINTERFACE_DISK, I get a different path value that lets me request the device number. That way I am able to get the link to the drive letter.
That path value obtained with GUID_DEVINTERFACE_DISK also contains the serial number but not the vendor and product IDs. But since both path values do contain the serial, it is no problem to get them both and build the relation.
I tested the code with Windows XP, 7 and 8 and it works fine. Only the FileCreate code of the code sample above must be adjusted (replace GENERIC_WRITE by 0). Otherwise Administrator rights or compatibility mode are required.
I did not try to find out what these different GUID values really stand for. Someone with a deeper knowledge in this area could probably provide a better explanation.
Best regards,
Florian

Detecting the platform of a Windows Store App

Is there a possibility to ask at runtime if a Windows Store app (compiled for ARM and x86/64) is executed currently on an ARM-device or more specific on a Microsoft Surface Tablet from within c# or is it necessary to compile two Versions of the same app to behave different on different plattforms?
This can be done via the following code (according to this SO post):-
[DllImport("kernel32.dll")]
internal static extern void GetNativeSystemInfo(ref SystemInfo lpSystemInfo);
internal static bool IsArmBased()
{
var sysInfo = new SystemInfo();
GetNativeSystemInfo(ref sysInfo);
return sysInfo.wProcessorArchitecture == ProcessorArchitectureArm; //ushort 5
}
This does pass the WACK test, test I wouldn't count on it being around forever. Think very hard about why you need this information (is it just for stats, or are you changing the behaviour of your app, if so why!?)
using Windows.ApplicationModel;
Package package = Package.Current;
PackageId packageId = package.Id;
String arch = String.Format("{0}", packageId.Architecture);
This will return "X86" or "ARM", depending on the underlying hardware.