https://github.com/tomconte/azure-iot-hub-php
Simple PHP Composer library to send data to Azure IoT Hub.
https://github.com/tomconte/azure-iot-hub-php
Last synced: 9 months ago
JSON representation
Simple PHP Composer library to send data to Azure IoT Hub.
- Host: GitHub
- URL: https://github.com/tomconte/azure-iot-hub-php
- Owner: tomconte
- Created: 2016-03-17T09:44:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-23T13:14:28.000Z (almost 10 years ago)
- Last Synced: 2025-03-29T10:05:13.678Z (9 months ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 5
- Watchers: 0
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A PHP library to send data to Azure IoT Hub
Currently the library is [hosted on my GitHub account](https://github.com/tomconte/azure-iot-hub-php), so in order to use it, your `composer.json` file should contain something like this:
~~~ json
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/tomconte/azure-iot-hub-php"
}
],
"require": {
"tomconte/azure-iot-hub": "dev-master"
}
}
~~~
This will load the Composer package directly from GitHub. Then you can use it that way:
~~~ php
sendEvent('Hello World!');
print($response->getStatusCode());
~~~
In order to find the values for `host`, `deviceId` and `deviceKey`, you can follow our [Get started with Azure IoT Hub](Get started with Azure IoT Hub) article. Basically, you will use the portal to create an IoT Hub, and then you will use our `iothub-explorer` command-line tool to generate a new device and its associated secret keys.
You can also use a connection string to create the client:
~~~ php
$connectionString = 'HostName=hubbhub.azure-devices.net;DeviceId=php_device;SharedAccessKey=xxxx';
$client = new DeviceClient($connectionString);
~~~
The `sendEvent()` method will open an HTTPS connection and send a single message. There is currently no provision to reuse the connection, since in PHP, objects are typically short-lived.
Please note that as with all IoT Hub libraries, your secret key is never sent on the wire. The library will compute a Shared Access Signature (SAS) token and use it to authenticate the communication; you can look at the `computeSAS()` function in the source code to see how this is done.
Please use the GitHub repo if you use this little library and have any feedback, questions or issues!