Closed osfrance closed 6 years ago
Hi make sure you are working with the requirements
its because of the version of mongodb. you have to downgrade
What version needs to be used? The Readme.md states
MongoDB v3.x server running
as requirement. findOne() seems to be deprecated since mongodb 2.2 somewhat. There are no docker images available on the official docker hub for versions <3.*
.
Orion itself says: The recommended MongoDB versions are 2.6/3.0/3.2/3.4.
Does this need a fix here?
Hi @mausquirk
This issue can be closed. The problem was about the version of mongoDB. As you said, requirement.findOne() is deprecated but it works for mongoDB version is >3.*
root@osboxes:/home/osboxes# gedit docker-compose.yml
version: '2' services: mongo: image: mongo:3.2 ports:
- "27010:27010" command: --nojournal orion: image: fiware/orion links:
- mongo ports:
- "1026:1026" command: -dbhost mongo
root@osboxes:/home/osboxes# docker ps -a
da8590af548c mongo:3.2 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:27010->27010/tcp, 27017/tcp demoapp_mongo_1
root@osboxes:/home/osboxes# docker inspect da8590af548c
"Tty":` false, "OpenStdin": false, "StdinOnce": false, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "GOSU_VERSION=1.7", "GPG_KEYS=DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \t42F3E95A2C4F08279C4960ADD68FA50FEA312927", "MONGO_PACKAGE=mongodb-org", "MONGO_REPO=repo.mongodb.org", "MONGO_MAJOR=3.2", "MONGO_VERSION=3.2.17"
root@osboxes:/home/osboxes# docker logs da8590af548c
2017-12-06T01:33:21.124+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=da8590af548c 2017-12-06T01:33:21.124+0000 I CONTROL [initandlisten] db version v3.2.17 2017-12-06T01:33:21.124+0000 I CONTROL [initandlisten] git version: 186656d79574f7dfe0831a7e7821292ab380f667
Reporter: Fernando Méndez Requena fernando.mendez.external@atos.net
I can confirm, that the mongo-binding works for mongo 3.2. Thanks
It would be great that the original reporter of the issue, @osfrance , could close the issue. However, if he cannot do it, I'll do that after the two possitive reports above (thanks @mausquirk and @fermenreq for the feedback!)
Same problem here.
When trying to create a new Service, an HTTP 500 response is received, with the message "{ "name": "TypeError", "message": "Cannot call method 'findOne' of undefined" }.
Example of non-working service creation request:
POST http://localhost:4041/iot/services
POST data:
{
"services": [
{
"apikey": "apikey11",
"cbroker": "http://127.0.0.1:1026",
"resource": "/iot/d",
"type": "thing"
}
]
}
[no cookies]
Request headers:
Connection: keep-alive
Content-Type: application/json
Fiware-Service: myHome
Fiware-ServicePath: /environment
Cache-Control: no-cache
When trying to create a device, no response is received, but the log of the agent shows this message too. Example of non-working device creation request:
POST http://localhost:4041/iot/devices
POST data:
{ "devices": [
{
"device_id": "sensor00",
"entity_name": "DTH22",
"entity_type": "multiSensor",
"attributes": [
{ "object_id": "t", "name": "Temperature", "type": "celsius" },
{ "object_id": "h", "name": "Humidity", "type": "string" }
],
"commands": [
{ "object_id": "l", "name": "setOn", "type": "string", "value":"OFF" }
]
}
]
}
[no cookies]
Request headers:
Connection: keep-alive
Content-Type: application/json
Fiware-Service: myHome
Fiware-ServicePath: /environment
Cache-Control: no-cache
Tested with various versions from Orion, MongoDB (3.2 and some others) and the docker and no docker versions of the Agent. Same problem with all of them.
Thanks in advance.
Reopning, as @carloslucenah is reporting the problem continues.
@mausquirk , @fermenreq , what do you think?
Hi @fgalan , @carloslucenah , @mausquirk
Attached you can see the flow and my requirements.:
root@osboxes:/home# docker --version
Docker version 17.09.1-ce, build 19e2cf6
root@osboxes:/home# npm --version
3.5.2
root@osboxes:/home# uname -a
Linux osboxes 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
root@osboxes:/home/osboxes/Desktop/Proyectos/iotagent-json#
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 82621f0cca28 fiware/orion "/usr/bin/contextB..." 37 hours ago Up 4 minutes 0.0.0.0:1026->1026/tcp supportiotagents_orion_1 c100df316b7b mongo:3.2 "docker-entrypoint..." 37 hours ago Up 4 minutes 0.0.0.0:27010->27010/tcp, 27017/tcp supportiotagents_mongo_1
root@osboxes:/home/osboxes/Desktop/Proyectos/iotagent-json# bin/iotagent-json config.js
time=2017-12-22T08:45:57.365Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.Global | srv=n/a | subsrv=n/a | msg=Activating IOT Agent NGSI Library. | comp=IoTAgent time=2017-12-22T08:45:57.368Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.Global | srv=n/a | subsrv=n/a | msg=MongoDB Device registry selected for NGSI Library | comp=IoTAgent time=2017-12-22T08:45:57.395Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=First connection attempt | comp=IoTAgent time=2017-12-22T08:45:57.396Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 1 | comp=IoTAgent time=2017-12-22T08:45:57.471Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Successfully connected to MongoDB. | comp=IoTAgent time=2017-12-22T08:45:57.529Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Starting IoT Agent listening on port [4041] | comp=IoTAgent time=2017-12-22T08:45:57.534Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Using config:
"logLevel": "DEBUG", "timestamp": true, "contextBroker": { "host": "172.24.0.2", "port": "1026" }, "server": { "port": 4041 }, "deviceRegistry": { "type": "mongodb" }, "mongodb": { "host": "172.24.0.3", "port": "27017", "db": "iotagentjson" }, "types": {}, "service": "howtoService", "subservice": "/howto", "providerUrl": "http://localhost:4041", "deviceRegistrationDuration": "P1M", "defaultType": "Thing", "iotaVersion": "1.6.0-next" }
| comp=IoTAgent time=2017-12-22T08:45:57.662Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Loading NGSI Contect server routes | comp=IoTAgent time=2017-12-22T08:45:57.666Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Loading access validation Templates | comp=IoTAgent time=2017-12-22T08:45:57.676Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Mongo Driver open | comp=IoTAgent time=2017-12-22T08:45:57.696Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentMQTT.Agent | srv=n/a | subsrv=n/a | msg=IoT Agent services activated | comp=IoTAgent time=2017-12-22T08:45:58.203Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IOTAJSON.AMQP.Binding | srv=n/a | subsrv=n/a | msg=Starting AQMP binding | comp=IoTAgent time=2017-12-22T08:45:58.210Z | lvl=FATAL | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.HTTPBinding | srv=n/a | subsrv=n/a | msg=GLOBAL-002: Configuration error. Configuration object [config.http] is missing | comp=IoTAgent {"op":"IOTAJSON.Executable","time":"2017-12-22T08:45:58.211Z","lvl":"INFO","msg":"JSON IoT Agent started"} time=2017-12-22T08:45:58.358Z | lvl=INFO | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent time=2017-12-22T08:45:58.358Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Recreating subscriptions for all devices | comp=IoTAgent time=2017-12-22T08:45:58.359Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent time=2017-12-22T08:45:58.362Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["/+/+/attrs/+","/+/+/attrs","/+/+/configuration/commands","/+/+/cmdexe"] | comp=IoTAgent time=2017-12-22T08:45:58.384Z | lvl=DEBUG | corr=7233c969-3477-49db-9864-5583abd7d342 | trans=7233c969-3477-49db-9864-5583abd7d342 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics: ["/+/+/attrs/+","/+/+/attrs","/+/+/configuration/commands","/+/+/cmdexe"] | comp=IoTAgent
curl -X POST -H "Fiware-Service: myHome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"devices": [
{
"device_id": "sensor00",
"entity_name": "DTH22",
"entity_type": "multiSensor",
"attributes": [
{ "object_id": "t", "name": "Temperature", "type": "celsius" },
{ "object_id": "h", "name": "Humidity", "type": "string" }
],
"commands": [
{ "object_id": "l", "name": "setOn", "type": "string", "value":"OFF" }
]
}
]
}' 'http://localhost:4041/iot/devices'
time=2017-12-22T08:49:16.271Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DeviceService | srv=myHome | subsrv=/environment | msg=Creating initial entity in the Context Broker:
{
"url": "http://172.24.0.2:1026/v1/updateContext",
"method": "POST",
"json": {
"contextElements": [
{
"type": "multiSensor",
"isPattern": "false",
"id": "DTH22",
"attributes": [
{
"name": "Temperature",
"type": "celsius",
"value": " "
},
{
"name": "Humidity",
"type": "string",
"value": " "
},
{
"name": "setOn_status",
"type": "commandStatus",
"value": "UNKNOWN"
},
{
"name": "setOn_info",
"type": "commandResult",
"value": " "
},
{
"name": "TimeInstant",
"type": "ISO8601",
"value": " "
}
]
}
],
"updateAction": "APPEND"
},
"headers": {
"fiware-service": "myHome",
"fiware-servicepath": "/environment",
"fiware-correlator": "675048d1-ff03-43eb-b706-4429a7399231"
}
}
| comp=IoTAgent time=2017-12-22T08:49:16.393Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DeviceService | srv=myHome | subsrv=/environment | msg=Initial entity created successfully. | comp=IoTAgent time=2017-12-22T08:49:16.438Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=myHome | subsrv=/environment | msg=Storing device with id [sensor00] and type [multiSensor] | comp=IoTAgent time=2017-12-22T08:49:16.550Z | lvl=ERROR | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.Alarms | srv=myHome | subsrv=/environment | msg=Releasing [MONGO-ALARM] | comp=IoTAgent time=2017-12-22T08:49:16.551Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DeviceProvisioning | srv=myHome | subsrv=/environment | msg=Device provisioning request succeeded | comp=IoTAgent time=2017-12-22T08:49:16.577Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=response-time: 985 | comp=IoTAgent
curl -X POST -H "Fiware-Service: myHome" -H "Fiware-ServicePath: /environment" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"services": [
{
"resource": "iot/d",
"apikey": "key",
"type": "multiSensor",
"cbroker":"172.20.0.3:1026"
}
]
}' 'http://localhost:4041/iot/services' ```
# Response from IotAgent
> time=2017-12-22T08:49:16.438Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=myHome | subsrv=/environment | msg=Storing device with id [sensor00] and type [multiSensor] | comp=IoTAgent
time=2017-12-22T08:49:16.550Z | lvl=ERROR | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.Alarms | srv=myHome | subsrv=/environment | msg=Releasing [MONGO-ALARM] | comp=IoTAgent
time=2017-12-22T08:49:16.551Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DeviceProvisioning | srv=myHome | subsrv=/environment | msg=Device provisioning request succeeded | comp=IoTAgent
time=2017-12-22T08:49:16.577Z | lvl=DEBUG | corr=675048d1-ff03-43eb-b706-4429a7399231 | trans=675048d1-ff03-43eb-b706-4429a7399231 | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=response-time: 985 | comp=IoTAgent
time=2017-12-22T09:09:42.258Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.GenericMiddlewares | srv=myHome | subsrv=/environment | msg=Request for path [/iot/services] from [localhost:4041] | comp=IoTAgent
time=2017-12-22T09:09:42.264Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.GenericMiddlewares | srv=myHome | subsrv=/environment | msg=Body:
```{
"services": [
{
"resource": "iot/d",
"apikey": "key",
"type": "multiSensor",
"cbroker": "172.20.0.3:1026"
}
]
} ```
> | comp=IoTAgent
time=2017-12-22T09:09:42.265Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.DeviceGroupService | srv=myHome | subsrv=/environment | msg=Creating new set of 1 services | comp=IoTAgent
time=2017-12-22T09:09:42.267Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.MongoDBGroupRegister | srv=myHome | subsrv=/environment | msg=Looking for entity params ["resource","apikey"] | comp=IoTAgent
time=2017-12-22T09:09:42.285Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.MongoDBGroupRegister | srv=myHome | subsrv=/environment | msg=Device group for fields [["resource","apikey"]] not found: [{"resource":"iot/d","apikey":"key"}] | comp=IoTAgent
time=2017-12-22T09:09:42.286Z | lvl=ERROR | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.Alarms | srv=myHome | subsrv=/environment | msg=Raising [MONGO-ALARM]: undefined | comp=IoTAgent
time=2017-12-22T09:09:42.291Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.MongoDBGroupRegister | srv=myHome | subsrv=/environment | msg=Storing device group with id [5a3ccbd6d3e08b15895412b4], type [multiSensor], apikey [key] and resource [iot/d] | comp=IoTAgent
time=2017-12-22T09:09:42.299Z | lvl=ERROR | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.Alarms | srv=myHome | subsrv=/environment | msg=Releasing [MONGO-ALARM] | comp=IoTAgent
time=2017-12-22T09:09:42.311Z | lvl=DEBUG | corr=cd861709-1226-4f2e-a7af-e8210441f1fd | trans=cd861709-1226-4f2e-a7af-e8210441f1fd | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=response-time: 52 | comp=IoTAgent
@carloslucenah , could you please post the complete log? My impression is that maybe the IOTA is not being able to connect to the mongoDB.
I have been trying to reproduce your problem with several versions of orion and mongo, with the IOTA in my native environment and also using docker, and all these tests have worked correctly.
Nevertheless, in my last test, I have turned off mongodB and the result when trying to create a device is just what you are reporting:
time=2017-12-23T10:56:11.158Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.Global | srv=n/a | subsrv=n/a | msg=Activating IOT Agent NGSI Library. | comp=IoTAgent
time=2017-12-23T10:56:11.184Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.Global | srv=n/a | subsrv=n/a | msg=MongoDB Device registry selected for NGSI Library | comp=IoTAgent
time=2017-12-23T10:56:11.361Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=First connection attempt | comp=IoTAgent
time=2017-12-23T10:56:11.363Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 1 | comp=IoTAgent
time=2017-12-23T10:56:11.701Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:11.702Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Waiting 5 seconds before attempting again. | comp=IoTAgent
time=2017-12-23T10:56:16.735Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 2 | comp=IoTAgent
time=2017-12-23T10:56:16.797Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:16.807Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Waiting 5 seconds before attempting again. | comp=IoTAgent
time=2017-12-23T10:56:21.827Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 3 | comp=IoTAgent
time=2017-12-23T10:56:21.829Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:21.829Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Waiting 5 seconds before attempting again. | comp=IoTAgent
time=2017-12-23T10:56:26.833Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 4 | comp=IoTAgent
time=2017-12-23T10:56:26.850Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:26.853Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Waiting 5 seconds before attempting again. | comp=IoTAgent
time=2017-12-23T10:56:31.858Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 5 | comp=IoTAgent
time=2017-12-23T10:56:31.859Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:31.860Z | lvl=ERROR | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-002: Error found after [5] attempts: MongoError: failed to connect to server [localhost:27017] on first connect | comp=IoTAgent
time=2017-12-23T10:56:31.862Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Starting IoT Agent listening on port [4041] | comp=IoTAgent
time=2017-12-23T10:56:31.863Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Using config:
{
"logLevel": "DEBUG",
"timestamp": true,
"contextBroker": {
"host": "localhost",
"port": "1026"
},
"server": {
"port": 4041
},
"deviceRegistry": {
"type": "mongodb"
},
"mongodb": {
"host": "localhost",
"port": "27017",
"db": "iotagentjson"
},
"types": {},
"service": "howtoService",
"subservice": "/howto",
"providerUrl": "http://localhost:4041",
"deviceRegistrationDuration": "P1M",
"defaultType": "Thing",
"iotaVersion": "1.6.0-next"
}
| comp=IoTAgent
time=2017-12-23T10:56:32.038Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Loading NGSI Contect server routes | comp=IoTAgent
time=2017-12-23T10:56:32.041Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Loading access validation Templates | comp=IoTAgent
time=2017-12-23T10:56:32.247Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentMQTT.Agent | srv=n/a | subsrv=n/a | msg=IoT Agent services activated | comp=IoTAgent
time=2017-12-23T10:56:32.865Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IOTAJSON.AMQP.Binding | srv=n/a | subsrv=n/a | msg=Starting AQMP binding | comp=IoTAgent
time=2017-12-23T10:56:32.881Z | lvl=FATAL | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.HTTPBinding | srv=n/a | subsrv=n/a | msg=GLOBAL-002: Configuration error. Configuration object [config.http] is missing | comp=IoTAgent
{"op":"IOTAJSON.Executable","time":"2017-12-23T10:56:32.884Z","lvl":"INFO","msg":"JSON IoT Agent started"}
time=2017-12-23T10:56:33.070Z | lvl=INFO | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=MQTT Client connected | comp=IoTAgent
time=2017-12-23T10:56:33.071Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Recreating subscriptions for all devices | comp=IoTAgent
time=2017-12-23T10:56:33.074Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Generating topics | comp=IoTAgent
time=2017-12-23T10:56:33.076Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Subscribing to topics: ["/+/+/attrs/+","/+/+/attrs","/+/+/configuration/commands","/+/+/cmdexe"] | comp=IoTAgent
time=2017-12-23T10:56:33.092Z | lvl=DEBUG | corr=da4df6a4-58e5-4121-8714-874a1b024ff8 | trans=da4df6a4-58e5-4121-8714-874a1b024ff8 | op=IoTAgentJSON.MQTTBinding | srv=n/a | subsrv=n/a | msg=Successfully subscribed to the following topics:
["/+/+/attrs/+","/+/+/attrs","/+/+/configuration/commands","/+/+/cmdexe"]
| comp=IoTAgent
time=2017-12-23T10:56:37.859Z | lvl=DEBUG | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.GenericMiddlewares | srv=myHome | subsrv=/environment | msg=Request for path [/iot/devices] from [localhost:4041] | comp=IoTAgent
time=2017-12-23T10:56:37.861Z | lvl=DEBUG | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.GenericMiddlewares | srv=myHome | subsrv=/environment | msg=Body:
{
"devices": [
{
"device_id": "sensor00",
"entity_name": "DTH22",
"entity_type": "multiSensor",
"attributes": [
{
"object_id": "t",
"name": "Temperature",
"type": "celsius"
},
{
"object_id": "h",
"name": "Humidity",
"type": "string"
}
],
"commands": [
{
"object_id": "l",
"name": "setOn",
"type": "string",
"value": "OFF"
}
]
}
]
}
| comp=IoTAgent
time=2017-12-23T10:56:38.016Z | lvl=DEBUG | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.DeviceProvisioning | srv=myHome | subsrv=/environment | msg=Handling device provisioning request. | comp=IoTAgent
time=2017-12-23T10:56:38.020Z | lvl=DEBUG | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.MongoDBGroupRegister | srv=myHome | subsrv=/environment | msg=Looking for entity params undefined | comp=IoTAgent
time=2017-12-23T10:56:38.021Z | lvl=ERROR | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=TypeError: Cannot read property 'findOne' of undefined | comp=IoTAgent
time=2017-12-23T10:56:38.021Z | lvl=DEBUG | corr=0fed2ab9-83c0-45cc-b8cd-eed38601652b | trans=0fed2ab9-83c0-45cc-b8cd-eed38601652b | op=IoTAgentNGSI.DomainControl | srv=myHome | subsrv=/environment | msg=response-time: 211 | comp=IoTAgent
Recreated the Orion and Mongo dockers via docker-compose. Started the agent. After that, tested that the database from the agent is created:
MongoDB shell version: 2.4.9
connecting to: test
> show databases
Warning 0.203125GB
**iotagentjson 0.203125GB**
local 0.078125GB
orion (empty)
But the surprise is that when launched a service creation request for catching the log... it worked! Repeated with the device creation... again successfully.
Seriously, I changed nothing from the last time. Maybe some node libraries have been updated in between. The fact is that right now is working.
Thanks for all!
After last @carloslucenah report, I'm closing this issue again.
If some of the others that have take part in the disussion (@dcalvoalonso , @mausquirk , @fermenreq) think different we can reopen it again :)
I am stuck and need your help. I have following Docker containers.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0d342bf05ee8 fiware/iotagent-ul "/bin/sh -c 'bin/iot…" 42 minutes ago Up 42 minutes 0.0.0.0:4041->4041/tcp, 0.0.0.0:7896->7896/tcp festive_torvalds 9d7ba0df6ea1 ansi/mosquitto "/usr/local/sbin/mos…" About an hour ago Up About an hour 0.0.0.0:1883->1883/tcp fiware_mosquitto_1 043e141290f5 fiware/orion "/usr/bin/contextBro…" About an hour ago Up About an hour 0.0.0.0:1026->1026/tcp fiware_orion_1 0edcd40bfc66 mongo:3.4 "docker-entrypoint.s…" About an hour ago Up 45 minutes 27017/tcp fiware_mongo_1
I am unable to create/get devices. In logs I found following errors.
time=2018-01-23T15:47:32.722Z | lvl=ERROR | corr=fc7b2b20-e109-410e-b868-d2ad76f2e040 | trans=fc7b2b20-e109-410e-b868-d2ad76f2e040 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [mongo:27017] on first connect | comp=IoTAgent
time=2018-01-23T15:51:14.684Z | lvl=DEBUG | corr=50b1da63-cd21-4683-a8ab-3963e9b25cb6 | trans=50b1da63-cd21-4683-a8ab-3963e9b25cb6 | op=IoTAgentNGSI.GenericMiddlewares | srv=/ | subsrv=/TechM/IoTRnD | msg=Error [TypeError] handling request: Cannot read property 'findOne' of undefined | comp=IoTAgent
time=2018-01-23T15:53:20.125Z | lvl=DEBUG | corr=e9aa6669-9d4d-40bf-bed8-1a5f8c501e0d | trans=e9aa6669-9d4d-40bf-bed8-1a5f8c501e0d | op=IoTAgentNGSI.GenericMiddlewares | srv=howtoService | subsrv=/howto | msg=Error [TypeError] handling request: Cannot read property 'find' of undefined | comp=IoTAgent
I followed below given steps.
orion: image: fiware/orion links:
Kindly guide what am I doing wrong? It seems that IoTAgent could not connect to Mongo DB but I am not sure what to change, where to change and how? Just FYI, I have Docker Containers on single Ubuntu 16.
Regards, Krishan
If I am not wrong, in the docker-compose.yml file you are not saying which ports must be published and exposed for mongo. Therefore, the rest of container cannot get access to it.
Hi @babbarkrishan,
Make sure you are using Mongo 3.2 version. I recommend you to use docker-compose. Doing that you can set up all ip address containers into the iotagent config file.
At the beginning of the issue, you can see my coment step by step and it works.
Regards
Thanks, I modified docker-compose.yml with following contents. Changed mongo db version from 3.4 to 3.2. But still getting same error. mongo: image: mongo:3.2 command: --nojournal ports:
Iot Agent Logs are given below with configuration (shown in logs) time=2018-01-24T13:21:10.926Z | lvl=INFO | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=Attempting to connect to MongoDB instance. Attempt 5 | comp=IoTAgent time=2018-01-24T13:21:11.022Z | lvl=ERROR | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoError: failed to connect to server [mongo:27017] on first connect | comp=IoTAgent time=2018-01-24T13:21:11.022Z | lvl=ERROR | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-002: Error found after [5] attempts: MongoError: failed to connect to server [mongo:27017] on first connect | comp=IoTAgent time=2018-01-24T13:21:11.032Z | lvl=INFO | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Starting IoT Agent listening on port [4041] | comp=IoTAgent time=2018-01-24T13:21:11.034Z | lvl=DEBUG | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.NorthboundServer | srv=n/a | subsrv=n/a | msg=Using config:
{ "logLevel": "DEBUG", "timestamp": true, "contextBroker": { "host": "orion", "port": "1026" }, "server": { "port": 4041 }, "deviceRegistry": { "type": "mongodb" }, "mongodb": { "host": "mongo", "port": "27017", "db": "iotagentul" }, "types": {}, "service": "howtoService", "subservice": "/howto", "providerUrl": "http://localhost:4041", "deviceRegistrationDuration": "P1M", "defaultType": "Thing", "iotaVersion": "1.5.0-next" } | comp=IoTAgent time=2018-01-24T13:21:11.089Z | lvl=INFO | corr=ed928f10-a746-40bc-ae4a-a439f8e2b708 | trans=ed928f10-a746-40bc-ae4a-a439f8e2b708 | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Loading NGSI Contect server routes | comp=IoTAgent
Thanks again for your quick responses.
Regards, Krishan
Please, change the host name in the config file of the IotAgent to the mongo IP address container.
Regards
@babbarkrishan the issue was closed and your issue seems to be new. For next time, it is better to open a new issue.
My two cents...
Thanks Guys, Using below given docker-compose.yml, things are working fine
mongo: image: mongo:3.2 command: --nojournal ports:
@fgalan, sure will keep it in mind.
Appreciate all for your help.
Regards, Krishan
Hi everyone, I am facing this problem right now, I tried suggestion in comments above but still getting the error. Please find below, docker-compose file I'm using.
version: "3.1"
services:
mongo:
image: mongo:3.2
command: --nojournal
ports:
- "27017:27017"
expose:
- "27017"
orion:
image: fiware/orion
links:
- mongo
ports:
- "1026:1026"
command: -dbhost mongo -logLevel DEBUG
depends_on:
- mongo
expose:
- "1026"
lightweightm2m-iotagent:
image: telefonicaiot/lightweightm2m-iotagent
hostname: idas
links:
- orion
expose:
- "4041"
- "5684"
ports:
- "4041:4041"
- "5684:5684/udp"
mosquitto:
image: ansi/mosquitto
ports:
- "1883:1883"
expose:
- "1883"
And the error still appears, as below:
{
"message": "Cannot read property 'findOne' of undefined",
"name": "TypeError"
}
It could be related (as all agents use the same ioagent-node-lib library, which is the one that deal with database operations), but note that this issue is in the https://github.com/telefonicaid/iotagent-json repository, while you are using https://github.com/telefonicaiot/lightweightm2m-iotagent.
In fact, it seems the issue has been already published in the IOTA LWM2M repository: https://github.com/telefonicaid/lightweightm2m-iotagent/issues/146
Yes, searching on for a solution and come across this, I am sorry. But the solutions suggested here doesn't work either.
Hello I am having the same problem here. I tried various configurations from this thread but I was not able to make it work. I work on the containerized fiware.
I follow this tutorial step by step https://fiware-tutorials.readthedocs.io/en/latest/iot-agent/index.html#provisioning-an-iot-agent
This command:
curl -iX POST 'http://localhost:4061/iot/services' -H 'Content-Type: application/json' -H 'fiware-service: openiot' -H 'fiware-servicepath: /' -d '{
"services": [
{
"apikey": "4jdsadwawdfee53ov",
"cbroker": "http://localhost:1026",
"entity_type": "Thing",
"resource": "/iot/d"
}
]
}'
Returns this: {"name":"TypeError","message":"Cannot read property 'findOne' of undefined"}
I tried various configurations of the yml file I attach both the original from docker hub and the latest I tried. Can someone help? docker-compose latest.txt
@nalexopo
I think this error has to do with mongodb. Try adding the host mongodb in your agent environment definition, i.e:
environment:
- IOTA_MONGO_HOST=mongo
Hello I also tried the other image I noticed you use in here (fiware/iotagent-json) and this has the same problem. It appears from the log that the mongodb can't connect to iotagent. However I have succesfully used orion context broker to store entities.
The log.
fiware-iot-agent | time=2019-05-17T12:33:17.394Z | lvl=ERROR | corr=699e620b-dc15-4d6d-bb06-02fe65597603 | trans=699e620b-dc15-4d6d-bb06-02fe65597603 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoNetworkError: failed to connect to server [mongo-db:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongo-db mongo-db:27017] | comp=IoTAgent
@arilwan It doesnt fix anything.
@nalexopo
Can you share your docker-compose file?
Hello I also tried the other image I noticed you use in here (fiware/iotagent-json) and this has the same problem. It appears from the log that the mongodb can't connect to iotagent. However I have succesfully used orion context broker to store entities.
The log.
fiware-iot-agent | time=2019-05-17T12:33:17.394Z | lvl=ERROR | corr=699e620b-dc15-4d6d-bb06-02fe65597603 | trans=699e620b-dc15-4d6d-bb06-02fe65597603 | op=IoTAgentNGSI.DbConn | srv=n/a | subsrv=n/a | msg=MONGODB-001: Error trying to connect to MongoDB: MongoNetworkError: failed to connect to server [mongo-db:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongo-db mongo-db:27017] | comp=IoTAgent
@arilwan It doesnt fix anything.
By the way, are you sure mongodb is starting successfully?
Mongo db starts as I understand from the logs and as I have tested doing some writes using the orion context broker API(which are persistent even if I shut down my pc). For some reason the mongo db is not connecting with iot agent if I understand the problem correct. I attach logs and original yml (fiware/iotagent-json)
Check the iot-agent service health:
curl -X GET 'http://localhost:4041/iot/about'
iot-agent seems fine
~$ curl -X GET 'http://localhost:4041/iot/about' {"libVersion":"2.8.0-next","port":"4041","baseRoot":"/","version":"1.9.0-next"}
What version of mongodb are you using?
From the log file, I can see ECONNREFUSED 127.0.0.1:5672
which service is using port 5672
?
From your docker-compose the iot-agent listens on port 7896
I tried 3.6 and 3.2 after reading here, but with no luck
I believe 5672 is the AMQP port but I dont plan using AMQP so I dont think I need this. I think the problem is that while orion context broker communicates with mongo db through 27017 the iotagent cant connect to the same port, as the scheme on iot agent tutorial suggests.
Can you share the docker-compse
file you currently use?
Looking to docker compose at https://github.com/telefonicaid/iotagent-json/files/3196881/docker-compose.latest.txt I see in the IOTA section:
- "IOTA_MONGO_HOST=mongo-db"
But the name of your MongoDB contiainer is mongodb
. In fact in the Orion section you use:
command: -dbhost mongodb
And as far as I understand by your reports Orion is working.
So maybe you should use:
- "IOTA_MONGO_HOST=mongodb"
In addition, I'd suggest removing:
hostname: mongo-db
container_name: db-mongo
which maybe are causing some naming conflict.
Hi, I try to create (and get) device from idas iot agentJSON/HTTP but I had error message in LOG :
GET FROM http://idas:4041/iot/services or POST return HTTP ERROR 500 :
I use docker image fiware/iotagent-json:latest
Thanks,