GroveStreams

PUT with body string and multiple feeds392

pat private msg quote post Address this user
I am using a PUT request with gzip

My bodystring is the following
bodystring='[{"compId":"1234","time":"1464583381000","comTmplId":"mote","streamId":"temperature","data":29.3}]'

It works good.

Now how would I format my bodystring to add the streamId:"humidity" and "data":60 for the same compId and same time and same template ?
Do I have to repeat all of it ? I have tried with arrays, comma separated but it doesn't work

Is my only way doing this is using the following code :
bodystring='[{"compId":"1234","time":"1464583381000","comTmplId":"mote","streamId":"temperature","data":19.3}, {"compId":"1234","time":"1464583381000","comTmplId":"mote","streamId":"humidity","data":60}]'

Isn't there anything shorter ?
Post 1 IP   flag post
MikeMills private msg quote post Address this user
Use the Advanced JSON API.

You can add multiple components, each with multiple streams, each with multiple sample times. The time array can be at any level of the JSON structure. For example, if it is at the feed level, then all stream sample values will be saved with that one set of times. This example below has times for each set of samples:

 
{
  "feed": {
    "component": [
      {
        "stream": [
          {
            "time": [
              1293840001001,
              1293840000999,
              1293840002000
            ],
            "streamId": "myStream1",
            "data": [
              "A sample data string2",
              "A sample data string1",
              "A sample data string3"
            ]
          },
          {
            "time": [
              1293840001001,
              1293840000999,
              1293840002000
            ],
            "streamId": "myStream2",
            "data": [
              6,
              3,
              8
            ]
          },
          {
            "time": [
              1293840001001,
              1293840000999,
              1293840002000
            ],
            "streamId": "myStream3",
            "data": [
              9.220000267028809,
              3.140000104904175,
              5.760000228881836
            ]
          }
        ],
        "componentId": "myComp1"
      }
    ]
  }
} 
Post 2 IP   flag post
MikeMills private msg quote post Address this user
Here's an example of one set of time:

 
 
{
  "feed": {
    "time": [
              1293840001001,
              1293840000999,
              1293840002000
      ],
    "component": [
      {
        "stream": [
          {
 
            "streamId": "myStream1",
            "data": [
              "A sample data string2",
              "A sample data string1",
              "A sample data string3"
            ]
          },
            "streamId": "myStream2",
            "data": [
              6,
              3,
              8
            ]
          },
            "streamId": "myStream3",
            "data": [
              9.220000267028809,
              3.140000104904175,
              5.760000228881836
            ]
          }
        ],
        "componentId": "myComp1"
      }
    ]
  }
} 
Post 3 IP   flag post
pat private msg quote post Address this user
It seems that your code is even longer then the second one in my post considering that I have one time.
For you what would be the shortest code you could get with my example 2 ? (same time, one data per feed) ?
Post 4 IP   flag post
MikeMills private msg quote post Address this user
Unformatted, yours is 191 characters, the advanced API is 178 characters. Here's what it would look like (formatted):

{
  "feed": {
    "time": [
      1464583381000
    ],
    "component": [
      {
        "comTmplId": "mote",
        "componentId": "1234",
        "stream": [
          {
            "streamId": "temperature",
            "data": [
              19.3
            ]
          },
          {
            "streamId": "humidity",
            "data": [
              60
            ]
          }
        ]
      }
    ]
  }
}


You could shorten it up by giving your stream small IDs such as "T" and "H". Give your template a smaller ID too.

Now, the All on the URL call is probably even shorter, but you can't compress that.

FYI, you can't pass the compTmplId as part of the JSON API call you had in your first post. It is part of the URL for that call.

Note that if you don't pass a sample time, the GS servers will set it for you at the time of the Feed PUT call. That would save some chars too.
Post 5 IP   flag post
pat private msg quote post Address this user
1) It seems that with the standard API I can upload different compId in the same body but it is not possible to use different comTmplId (as it is in the http request), is that correct ?

2)With the advanced API, I didn't see how I can upload data for multiple compId and multiple streams is that possible ?
Post 6 IP   flag post
MikeMills private msg quote post Address this user
1. Yes
2. Yes. The JSON structure supports an Array of component and an Array of Streams for each component:

 
 
{
  "feed": {
    "time": [
      1464583381000
    ],
    "component": [
      {
        "comTmplId": "T1",
        "componentId": "Comp1",
        "stream": [
          {
            "streamId": "tmp",
            "data": [
              19.3
            ]
          },
          {
            "streamId": "hum",
            "data": [
              60
            ]
          }
        ]
      },
      {
        "comTmplId": "T2",
        "componentId": "Comp2",
        "stream": [
          {
            "streamId": "tmp",
            "data": [
              19.3
            ]
          },
          {
            "streamId": "hum",
            "data": [
              60
            ]
          }
        ]
      }
    ]
  }
}
 
 
Post 7 IP   flag post
pat private msg quote post Address this user
Sorry I meant for point 2. for multiple compId and multiple streams is that possible with a time different for each ComponentId
Post 8 IP   flag post
MikeMills private msg quote post Address this user
Yes, just move the time JSON attribute to under each component:

{
  "feed": {
    "component": [
      {
        "comTmplId": "T1",
        "componentId": "Comp1",
        "time": [
          1464583381000
        ],
        "stream": [
          {
            "streamId": "tmp",
            "data": [
              19.3
            ]
          },
          {
            "streamId": "hum",
            "data": [
              60
            ]
          }
        ]
      },
      {
        "comTmplId": "T2",
        "time": [
          1464583382000
        ],
        "componentId": "Comp2",
        "stream": [
          {
            "streamId": "tmp",
            "data": [
              19.3
            ]
          },
          {
            "streamId": "hum",
            "data": [
              60
            ]
          }
        ]
      }
    ]
  }
}
Post 9 IP   flag post
pat private msg quote post Address this user
Hi,

I am pushing data for different customers and each customer has its own API key.

Is it possible with a single PUT to push data with different API_KEY ?

Or when doing a PUT, all data must use the same API_KEY ?
Post 10 IP   flag post
MikeMills private msg quote post Address this user
Quote:
Originally Posted by pat
Is it possible with a single PUT to push data with different API_KEY ?
- No

Quote:
Originally Posted by pat
Or when doing a PUT, all data must use the same API_KEY ?
- Yes
Post 11 IP   flag post
2965 11 11
Log in or sign up to compose a reply.