2

I am trying to model my DB in MYSQL, I would like my structure to be formed by a data collection table, which would be the one that generates cygnus automatically, then its subsequent related tables for those data with greenhouses and users.

All the data of all the sensors of each users in a table and then relate this to each user and greenhouse, I think it would be the correct way.

But I'm trying to create two subscriptions one that meta data in this table for an entity ID and another for another entity ID, but it automatically creates me two tables and the idea is to be all in one.

How could this be done?

enter image description here

I attach my entities:

GET /v2/entities/ HTTP/1.1
Host: 1.2.3.4:1026
Accept: application/json
Content-Type: application/json
Fiware-Service: pruebastienda
Fiware-ServicePath: /tienda1
Cache-Control: no-cache
Postman-Token: e19de386-ca21-cd7d-cd24-f1dee9487196   

 [
        {
            "id": "palmerillas",
            "type": "invernadero",
            "pressure2": {
                "type": "Integer",
                "value": 6,
                "metadata": {}
            },
            "sensor32": {
                "type": "Integer",
                "value": 1,
                "metadata": {}
            },
            "sensor42": {
                "type": "Integer",
                "value": 44,
                "metadata": {}
            },
            "temperature2": {
                "type": "float",
                "value": 4,
                "metadata": {
                    "accuracy": {
                        "type": "Float",
                        "value": 9
                    }
                }
            }
        },
        {
            "id": "palmerillas2",
            "type": "invernadero2",
            "pressure2": {
                "type": "Integer",
                "value": 6,
                "metadata": {}
            },
            "sensor32": {
                "type": "Integer",
                "value": 1,
                "metadata": {}
            },
            "sensor42": {
                "type": "Integer",
                "value": 44,
                "metadata": {}
            },
            "temperature2": {
                "type": "float",
                "value": 4,
                "metadata": {
                    "accuracy": {
                        "type": "Float",
                        "value": 9
                    }
                }
            }
        }
    ]

And my subscriptions as well:

GET /v2/subscriptions/ HTTP/1.1
Host: 1.2.3.4:1026
Accept: application/json
Fiware-Service: pruebastienda
Fiware-ServicePath: /tienda1
Cache-Control: no-cache
Postman-Token: 7898a397-2018-42fc-7edf-e35f25105901

    [
        {
            "id": "59ca8b394df7c75fee3e1969",
            "description": "A subscription to get info about palmerillas",
            "status": "active",
            "subject": {
                "entities": [
                    {
                        "id": "palmerillas",
                        "type": "invernadero"
                    }
                ],
                "condition": {
                    "attrs": [
                        "pressure2"
                    ]
                }
            },
            "notification": {
                "timesSent": 2,
                "lastNotification": "2017-09-26T17:16:04.00Z",
                "attrs": [
                    "temperature2",
                    "pressure2",
                    "sensor32",
                    "sensor42"
                ],
                "attrsFormat": "legacy",
                "http": {
                    "url": "http://localhost:5050/notify"
                },
                "lastSuccess": "2017-09-26T17:16:04.00Z"
            }
        },
        {
            "id": "59ca8bb94df7c75fee3e196a",
            "description": "A subscription to get info about palmerillas",
            "status": "active",
            "subject": {
                "entities": [
                    {
                        "id": "palmerillas2",
                        "type": "invernadero2"
                    }
                ],
                "condition": {
                    "attrs": [
                        "pressure2"
                    ]
                }
            },
            "notification": {
                "timesSent": 2,
                "lastNotification": "2017-09-26T17:17:56.00Z",
                "attrs": [
                    "temperature2",
                    "pressure2",
                    "sensor32",
                    "sensor42"
                ],
                "attrsFormat": "legacy",
                "http": {
                    "url": "http://localhost:5050/notify"
                },
                "lastSuccess": "2017-09-26T17:17:56.00Z"
            }
        }
    ]

EDIT:

The names of the tables are:

tienda1_palmerillas_invernadero AND tienda1_palmerillas2_invernadero2

as you can see in the picture

frb
  • 3,738
  • 2
  • 21
  • 51
Manolait
  • 353
  • 2
  • 11
  • Could you refine your question, please? I'm not able to understand if you have a problem with Orion's subscriptions, or with Cygnus persistence in MySQL. If you can post any error message, it would be great as well! Thanks :) – frb Sep 27 '17 at 06:33
  • Could you edit your question post to include the name of the tables that are being generated at MySQL, please? Thx! – fgalan Sep 27 '17 at 07:53
  • 1
    Piece of advice: don't post your public IPs in the public Internet :) Better use an ofuscated version, e.g. 150.214.y.z. – fgalan Sep 27 '17 at 07:54
  • jajaja, you're right with the IP. I want to put in the same table different entity ID and type. Just that, I do not have any errors of any kind, only that I create two tables even putting the same Fiware-Service and Fiware-ServicePath @fgalan – Manolait Sep 27 '17 at 09:16
  • I want to put in a same table several entity ids – Manolait Sep 27 '17 at 09:40
  • You said Cygnus create two tables. Which is the name of these two tables? Could you edit your question post to include that information, please? Thanks! – fgalan Sep 27 '17 at 10:36
  • Edit post @fgalan – Manolait Sep 27 '17 at 11:33

1 Answers1

1

If I've understood well, you need to use Cygnus' Grouping Rules (GR). Or, available in recent versions, Name Mappings (NM); similar to Grouping Rules, but more effcient and flexible.

In a few words, GR (or NM) allows you to play with the name of the backend storage element (in the case of MySQL, the name of the tables the data is stored). By default, such name is based on the concatenation of the entity_id and entity_type (plus other prefixes, as is the case of MySQL, where the FIWARE service path is prefixed). Nevertheless, using GR (or NM), you can alter such concatenation:

  • GR directly allow you to change the complete concatenation of entity_id and entity_type, specifying, for instance, you want information regarding all entities of type car is stored in a all_cars table.
  • NM does the replacement in a more fine grained way, allowing you to modify either the entity_id, either the entity_type, or both (even, much more evil options are available :-)). For instance, you can say you want to replace all entity IDs by all and the car entity type by cars; in the end you'll have the same behaviour than GR: all_cars.

Please observe, replacements only affect the naming proceses; the data stored in the tables remains unaltered.

Please, have a look on GR documentation. And NM as well.

frb
  • 3,738
  • 2
  • 21
  • 51
  • Hello, I have read that in the last version you have to use Name Mappings better, but I do not want to replace the names of each entity. IMPORTANT NOTE: from release 1.6.0, this feature is deprecated in favor of Name Mappings. More details can be found here. I have version 1.7.0 I want to save different entities and different subscriptions in the same table. Do I have to use Grouping rules? a greeting. – Manolait Oct 02 '17 at 11:20
  • As I'm telling you "replacements only affect the naming processes; the data stored in the tables remains unaltered". This means if you have two entities identified as "car1" and "car2" of type "car", you can decide to map the entity IDs to "all_my", and to map the entity type to "cars", and in the end you'll have a table name "all_my_cars". But the rows within the table will maintain the original entity IDs and type, i.e. "car1", "car2" and "car". – frb Oct 02 '17 at 14:45
  • OK I understand. then as my version is 1.7.0 is it recommended to use Grouping rules or Name Mappings? Thank you – Manolait Oct 02 '17 at 18:34
  • Name Mappings. They deprecate Grouping Rules, which are less flexible and make internally the code less efficient. – frb Oct 03 '17 at 06:36