Updating BLE Device Firmware in iOS - ios

In my current iOS project, I need to upgrade the current firmware of the BLE device on availability of a newer version. And the server is providing me the data that sample format
{
"fileId": "687659c1-02be-48b9-97bf-37472bcbc9b6",
"length": 143184,
"createdDate": 1426010825894,
"version": "0.34",
"packets": [
{
"address": "00008000",
"data": "0041002091F3000035E100008DF300008DF300008DF300008DF30000000000000000000000000000000000008DF300008DF30000000000008DF30000ADAD00008DF30000C1E40000D1E40000E1E40000F1E4000001E5000011E5000021E5000031E5000041E5000051E5000061E5000071E5000081E5000091E50000A1E50000B1E500008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF30000ADDE00008DF300008DF300008DF30000C9AD000045E1000055E1000065E1000075E1000085E1000095E10000A5E10000B5E100008DF300008DF300008DF300008DF300008DF300008DF300008DF300008DF3000015F100008DF3000029F100008DF300008DF300008DF300008DF300008DF300007DDC00008DF300008DF300008DF300008DF300008DF300008DF300008DF300003DF1000051F100008DF3000008B50548054B1B1A062B00D808BD044B002BFBD09847F9E7743C0100773C01000000000008B50748074B1B1A9B1003EBD373591000D108BD044A002AFBD09047F9E700BF743C0100743C01000000000010B5064C237843B9FFF7D2FF044B13B10448AFF300800123237010BDD80E002000000000743C010008B5084B1BB10848"
},
{
"address": "00008200",
"data": "0849AFF300800848036813B1074B03B19847BDE80840FFF7C5BF00BF00000000743C0100DC0E0020743C01000000000070B50E46154678B914467119002CC4EB010106DD064B1868064B1B689847013CF3E725EAE57070BD4FF0FF3070BD00BF68300020201100200C4B1A6882B0920354BFD12240F2DD220192019AD2080192019A511E0191002AFAD140F0AA4240F02A401A60186002B0704700BF000C0F4010220023027201220360436043728272C27203734373704770B50C46154680E83000274B0846984723681E0746D42368244E13F0010F03D12368D8030FD507E0206820F00100B0472368D907FCD4F3E7206820F48030B0472368DA03FCD495E80C00287A697A0002134300F4F8501843AB7A8904002BEB7A01F4F80140EA010014BF80210021002B2B7B40EA01000CBF00210221002B40EA01000CBF002310231843B047206840F48030B0472368DB03FCD52046044B9847012070BD002070BD8DD400006982000051D7000038B590E830000C4B204698472B7B13B10423E361E3606B7B2068002B0CBF0023082340F001001843044B9847044B1B68DB07FBD538BD00BF8DD4000069820000000C0F4003689A689207FCD5024A5A6002F1AA425A607047010000557FB50E4B02A8984707238DF8103001238DF8133068460A490A4B02AA984748B172B6BFF35F8F084B00221A706846074B9847FEE707B05DF8"
}
],
"type": "application/octet-stream",
"name": "nextgen_0_34.hex"
}
I am aware of the method of writing data to a CBPeripheral by calling method
[peripheral writeValue:dataToWrite forCharacteristic:interestingCharacteristic
type:CBCharacteristicWriteWithResponse];
My questions are:
How can I use these addresses while creating a CBMutableCharacteristic?
I am getting about 120 packets. Is there a way that I can write data one by one so that I can show a progress to user?

Related

Thingsboard Upload Converter with multiple timestamps

My device takes measuremets more often than it communicates with MQTT broker, so there can be more than one timestamb in each message, like this:
my/device/telemetry 1651396728000:22,13;1651400328000:25,10;...so on
I want to use built-in Thingsboard MQTT Integration with my custom Upload Converter, but I can't find proper format for result object with multiple timestamps in it (how it was in Gateway Telemetry API)
The output of your data converter should be an array like this:
var result = [
{
"deviceName": "88888888",
"deviceType": "tracker",
"attributes": {
"att1": "val1",
},
"telemetry": {
"ts": 1652738915000,
"values": {
"blah": "blooo",
"External Voltage": 12812
}
}
},
{same},
{similar}
]

Can't read data from Firebase Realtime database by issuing a GET request. Always returns null

Task is simple, but I couldn't find any solution though.
Here is the request I'm sending https://graf-24561-default-rtdb.firebaseio.com/graf-24561-default-rtdb.json
Rules for reading and writing:
{
"rules": {
".read": "now < 1651165200000", // 2022-4-29
".write": "now < 1651165200000", // 2022-4-29
}
}
Data in code:
[
{
"name": "0002 М ( мрамор) 8м пленка с\/м\/20 DEKORON ",
"price": 209.7
},
{
"name": "0007 М ( мрамор) 8м пленка с\/м\/20 DEKORON ",
"price": 209.7
},
{
"name": "0008-2 А (дуб темный) 8м пленка с\/м \/20",
"price": 232.84
},
{
"name": "0008-3 А (темн.махагон) 8м пленка с\/м \/20 ",
"price": 209.7
}
]
The graf-24561-default-rtdb that you see in the root of the JSON in the screenshot is the name of your database, and is not part of the data structure.
So to get the entire database, the URL would be:
https://graf-24561-default-rtdb.firebaseio.com/.json
It may read a bit weird with that .json at the end, but is the correct syntax.

How To Convert "created_timestamp" Value To A Valid Date In Python

I'm currently working on a Twitter bot that automatically reply messages, I'm doing this by using tweepy (the official python twitter library)
I need to filter messages based on the created time as I don't want to reply same message twice. Now the problem is that the API endpoint returns created_timestamp as string representation of positive integers.
Below is an example of data returned as per the doc
{
"next_cursor": "AB345dkfC",
"events": [
{ "id": "110", "created_timestamp": "1639919665615", ... },
{ "id": "109", "created_timestamp": "1639865141987", ... },
{ "id": "108", "created_timestamp": "1639827437833", ... },
{ "id": "107", "created_timestamp": "1639825389806", ... },
{ "id": "106", "created_timestamp": "1639825389796", ... },
{ "id": "105", "created_timestamp": "1639825389768", ... },
...
]
}
My question is "How do I convert the created_timestamp to a valid date using python" ?.
You might play with timestamps on this resource
And in your case could use methods like:
timestamp = int('timestamp_string')
datetime.fromtimestamp(timestamp, tz=None)
date.fromtimestamp(timestamp)
From the datetime standard library. But integers after the first line are already well comparable if the task is to distinguish differences between the timestamps.

Twitter API 2.0 - Unable to fetch user.fields

I am using API version 2.0 and unable to fetch the user.fields results. All other parameters seem to be returning results correctly. I'm following this documentation.
url = "https://api.twitter.com/2/tweets/search/all"
query_params = {
"query": "APPL",
"max_results": "10",
"tweet.fields": "created_at,lang,text,author_id",
"user.fields": "name,username,created_at,location",
"expansions": "referenced_tweets.id.author_id",
}
response = requests.request("GET", url, headers=headers, params=query_params).json()
Sample result:
{
'author_id': '1251347502013521925',
'text': 'All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl',
'lang': 'en',
'created_at': '2021-06-05T02:33:48.000Z',
'id': '1401004298738311168',
'referenced_tweets': [{
'type': 'retweeted',
'id': '1401004298738311168'
}]
}
As you can see, the following information is not returned: name, username, and location.
Any idea how to retrieve this info?
Your query does actually return the correct data. I tested this myself.
A full example response will be structured like this:
{
"data": [
{
"created_at": "2021-06-05T02:33:48.000Z",
"lang": "en",
"id": "1401004298738311168",
"text": "All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl",
"author_id": "1251347502013521925",
"referenced_tweets": [
{
"type": "retweeted",
"id": "1401004298738311168"
}
]
}
],
"includes": {
"users": [
{
"name": "Gary Casper",
"id": "1251347502013521925",
"username": "Hisel1979",
"created_at": "2020-07-11T13:39:58.000Z"
}
]
}
}
The sample result you provided comes from within the data object. However, the expanded object data will be nested in the includes object (in your case name, username, and location). The corresponding user object can be referenced via the author_id field.

Create a sensor with SensorDataUnitType

I'm trying to create a new device with sensor(s).
This is the payload I'm sending to create the new device:
{"Name":"DeviceABC","HardwareId":"D4xxx425","SpaceId":"xxxx-xxx-xx-xx-xxx","Status":"Provisioned","CreateIoTHubDevice":false,"Properties":[{"Name":"VendorName","Value":"MyVendor"},{"Name":"VendorDeviceId","Value":"D4xxx19425"},{"Name":"VendorDeviceType","Value":"electricity"}],"Sensors":[{"pollRate":0,"id":null,"dataType":"Json","dataUnitType":"KilowattHourEnergy","deviceId":null,"portType":null,"port":"electricity","spaceId":null,"type":"Classic"}]}
In this case I want to use a built in type. KWh
{
"id": 186,
"category": "SensorDataUnitType",
"name": "KilowattHourEnergy",
"disabled": false,
"logicalOrder": 0,
"friendlyName": "kWh"
}
The SensorDataType is :
{
"id": 314,
"spaceId": "xxxx-xx-xxx-xx-xxxx",
"category": "SensorDataType",
"name": "Json",
"disabled": false,
"logicalOrder": 0
}
When I do this for other devices without specifying a dataUnitType in the sensor object, it works fine. But as soon as I include it i get this:
{
"error": {
"code": "400.600.000.000",
"message": "Invalid datatype/dataunittype combination used on sensor."
}}
There seems to be a naming convention between SensorDataType and SensorDataUnitType. The convention is that the SensorDataUnitType needs to end with the full SensorDataType. In your example you have:
"dataType":"Json",
"dataUnitType":"KilowattHourEnergy",
But according to the convention it should be
"dataType":"Json",
"dataUnitType":"KilowattHourEnergyJson",
Of course you can't just change KilowattHourEnergy because it's in a system ontology. So to get it working I had to create KilowattHourEnergyJson as a new type.
I guess the most complete answer would include that in your case the SensorDataType probably shouldn't be JSON but should be Energy.

Resources