Open girishkumarbk opened 6 years ago
@girishkumarbk I took a look at this since you referred to it in the iot-edge repo. I don't have experience with these sample modules, but maybe I can at least help you get the gateway started without errors.
The instructions in this repo's readme.md are a little vague about the directories from which you do the various operations. Here's what I did (I won't be extremely detailed either, but hopefully this helps):
git clone https://github.com/Azure-Samples/iot-gateway-mqtt-http.git
cd iot-gateway-mqtt-http
npm install
npm pack # produces iot-gateway-mqtt-http.tgz
cd ..
git clone https://github.com/Azure/iot-edge.git
cd iot-edge
v1/tools/build_nodejs.sh # takes forever
export NODE_INCLUDE="path/to/iot-edge/v1/build_nodejs/dist/inc"
export NODE_LIB="path/to/iot-edge/v1/build_nodejs/dist/lib"
v1/tools/build.sh --enable-nodejs-binding --disable-native-remote-modules --disable-ble-module
cd v1/samples/nodejs_simple_sample/nodejs_modules
npm install #if you're going to use iothub_writer.js (see below)
cd ../../../build/samples/nodejs_simple_sample
npm install path/to/iot-gateway-mqtt-http/iot-gateway-mqtt-http.tgz
openssl genrsa -out tls-key.pem 2048
openssl req -new -sha256 -key tls-key.pem -out tls-csr.pem
openssl x509 -req -in tls-csr.pem -signkey tls-key.pem -out tls-cert.pem
This puts all the needed binaries, node.js packages, and certs into the same directory.
Now you can edit iot-edge/samples/nodejs_simple_sample/src/gateway_sample_lin.json
. Remove all the existing entries from the "modules" array except for "iothub_writer" (or you could copy over the "iothub" and "mapper" module entries from iot-edge/v1/samples/simulated_device_cloud_upload/src/simulated_device_cloud_upload_lin.json
--that's what I did), and add in the "mqtt" and "http" module entries as described in this repo's readme.md. You'll also need to replace the "links" array with the values from the readme.md. Finally, you'll need to add any connection string information (or device ID/key for "iothub"). Then you'd run it like this:
./nodejs_simple_sample ../../../samples/nodejs_simple_sample/src/gateway_sample_lin.json
I was able to run the sample. I didn't try connecting to either of the servers; I'll leave that to you. ;)
I seem to get this error while starting the nodejs_simple_sample ...
./nodejs_simple_sample ../../../samples/nodejs_simple_sample/src/gateway_sample_lin.json ERROR: Error: Cannot find module 'azure-iot-device-amqp'
Also is "iothub" module different from "iothubwriter" ?
@girishkumarbk The "iothub" module is written in C, and is the official module used in IoT Edge v1 for sending messages to IoT Hub. "iothub_writer" is more of a basic sample written in JavaScript. If you're just trying to get something going for the first time, either will work and iothub_writer might be easier to use. But if this turns into a long-term project you'd probably want to move to the iothub module.
RE the error, that's a missing Node.js dependency (azure-iot-device-amqp) in iothub_writer. I updated my instructions above, but basically you need to:
cd v1/samples/nodejs_simple_sample/nodejs_modules
npm install
I encountered ERROR: Error: Cannot find module 'memdown'
I resolved the same by updating the dependency in the package.json at node_modules/iot-gateway-mqtt-http/package.json: "memdown":"^2.0.0"
Able to run the sample with updated gateway_sample_lin.json to have mqtt->logger->iothub flow.. ./nodejs_simple_sample ../../../samples/nodejs_simple_sample/src/gateway_sample_lin.json
However, I see that when I push the messages into the mqtt broker via simple python mqtt clients (import paho.mqtt.client as mqtt) the message are not appearing in mqtt broker nor I'm able to see in the node that has subscribed for the topic of interest. Most of the time the broker is "segment faulting" in libnodejs library.
Couple of questions 1.0 Isn't the broker pass on the message to iothub or say logger in this case, if the links are provided in .json. Meaning mqtt->logger->iothub ? how to we achieve this ? 2.0 Does the mqtt broker republish the message to iotedge broker so that it could be caught by other modules like logger and iothub for processing.
Any thing missing ? please comment
So there are two pipelines: (1) all messages go to the logger, and (2) messages flow from mqtt to mapper to iothub and (optionally) back.
If you’re seeing a segfault, you should post the output of running the app so we can see it.
I made the links changes as noted above. Still I see no messages in broker and it segfaults. Here is one such ..
MQTT Broker running.
Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffec353700 (LWP 19643)] 0x00007fffeea9001e in v8::internal::RememberedSet<(v8::internal::PointerDirection)1>::ClearInvalidSlots(v8::internal::Heap*) () from ../../bindings/nodejs/libnodejs_binding.so (gdb) bt
from ../../bindings/nodejs/libnodejs_binding.so
from ../../bindings/nodejs/libnodejs_binding.so
from ../../bindings/nodejs/libnodejs_binding.so
from ../../bindings/nodejs/libnodejs_binding.so
from /root/exp/iot-edge/v1/build_nodejs/dist/lib/libnode.so.48
at /root/exp/iot-edge/v1/bindings/nodejs/src/modules_manager.cpp:259
at /root/exp/iot-edge/v1/bindings/nodejs/src/modules_manager.cpp:272
(gdb)
Second .. seg fault
MQTT Broker running. Error in `/root/exp/iot-edge/v1/build/samples/nodejs_simple_sample/nodejs_simple_sample': double free or corruption (out): 0x00007fffe40f5990
Program received signal SIGABRT, Aborted. [Switching to Thread 0x7fffec353700 (LWP 19761)] 0x00007ffff6fc0c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt
at ../sysdeps/posix/libc_fatal.c:175
from /root/exp/iot-edge/v1/build_nodejs/dist/lib/libnode.so.48
from ../../bindings/nodejs/libnodejs_binding.so
from ../../bindings/nodejs/libnodejs_binding.so
---Type <retu
Are you building Node.js by calling v1/tools/build_nodejs.sh
without any arguments? Or are you doing something different (like passing the --node-version
argument, or building Node.js a different way)?
Also, you provided two different call stacks: the segfault and the double free. Are these happening at the same time in the same run, or did they happen separately during different runs? Did they happen as soon as you started the app, or after you tried to connect an MQTT client, or when the client sent its first message, or something else?
Are you building Node.js by calling v1/tools/build_nodejs.sh without any arguments?
The segfaults happen at different times in different runs. Some times I see segfault at the first mqtt connection and sometimes after few attempts to connection and publishing data is made. The segfaults are not consistent.
Thanks.
OK, at this point it sounds like you're running into problems with the sample itself rather than the Azure IoT Edge v1 libraries (not ruling it out, of course, but that's what it looks like to me). I don't think I can offer much more assistance, but the sample's maintainers might have more information for you.
Ok. Thanks for your support on this issue. Wondering ... 1.0) If the Azure mqtt sample maintainers are looking into issues in this repositories ? 2.0) I still feel v1 edge main repository should have had the mqtt/http module with it.
Do you see any reason why the git repository URL is mentioned differently in the repository README
git clone --recursive https://github.com/Azure/azure-iot-gateway-sdk.git git checkout 287beed07490d98a24a4e9ddd33ec7127fc3acbf
The URL is different (Its not pointing to Azure samples) Does this work only particular checkout "287beed07490d98a24a4e9ddd33ec7127fc3acbf" ?
The iot-edge repo used to be named azure-iot-gateway-sdk. And when you rename a GitHub repo, the old name continues to work.
I get this error when running this command. Any help ....
root@scson0016991001:~/cb/tmp/azure-iot-gateway-sdk/tools# npm install iot-gateway-mqtt-http --save npm http GET https://registry.npmjs.org/iot-gateway-mqtt-http npm http 404 https://registry.npmjs.org/iot-gateway-mqtt-http npm ERR! TypeError: Cannot read property 'latest' of undefined npm ERR! at next (/usr/share/npm/lib/cache.js:687:35) npm ERR! at /usr/share/npm/lib/cache.js:675:5 npm ERR! at saved (/usr/share/npm/node_modules/npm-registry-client/lib/get.js:142:7) npm ERR! at /usr/lib/nodejs/graceful-fs/polyfills.js:133:7 npm ERR! at Object.oncomplete (fs.js:107:15) npm ERR! If you need help, you may report this log at: npm ERR! http://github.com/isaacs/npm/issues npm ERR! or email it to: npm ERR! npm-@googlegroups.com
npm ERR! System Linux 3.13.0-32-generic npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "iot-gateway-mqtt-http" "--save" npm ERR! cwd /root/cb/tmp/azure-iot-gateway-sdk/tools npm ERR! node -v v0.10.25 npm ERR! npm -v 1.3.10 npm ERR! type non_object_property_load npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /root/cb/tmp/azure-iot-gateway-sdk/tools/npm-debug.log npm ERR! not ok code 0