# Create a device with sdk

**URL:** <https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968>\
**Category:** Module Development\
**Created:** [February 13, 2018, 4:55pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968 "2018-02-13T16:55:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 13, 2018, 4:55pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/1 "2018-02-13T16:55:41Z")

</div>

I don’t find in the SDK javadoc how to create a device.  
I would like to achieve it from a driver module in order to bulk create device.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 13, 2018, 4:58pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/2 "2018-02-13T16:58:23Z")

</div>

Are you trying to bulk create instances a driver type provided by your module or of some other module?

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 13, 2018, 5:02pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/3 "2018-02-13T17:02:07Z")

</div>

@Kevin.Herron, a driver type provided by my module

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 13, 2018, 5:04pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/4 "2018-02-13T17:04:06Z")

</div>

Ok, using the `PersistenceInterface` from `GatewayContext`, create a new instance of `DeviceSettingsRecord` and of your driver type’s setting record, point the one at the other, then make sure to call `PersistenceInterface#notifyRecordAdded` with the `DeviceSettingsRecord` instance.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 13, 2018, 5:11pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/5 "2018-02-13T17:11:56Z")

</div>

@Kevin.Herron, My module is an AbstractTagDriver,  
from the DriverContext and can’t reach the context.getPersistenceInterface() ?

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 13, 2018, 5:15pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/6 "2018-02-13T17:15:00Z")

</div>

oops, driverContext.getGatewayContext().getPersistenceInterface() will do the job,

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 13, 2018, 5:17pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/7 "2018-02-13T17:17:09Z")

</div>

Your module hook gets a `GatewayContext` too, which is likely the one you’ll want to use. I don’t see how bulk creating instances of a driver from within an instance of the driver itself makes any sense.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 13, 2018, 5:23pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/8 "2018-02-13T17:23:42Z")

</div>

I have lots of device to create with a “device model” (common parameters and only IP address which vary)

I create a “device model” with the ignition gateway webpage, with the common settings for all the others and a list of IP adress. The “device model” create the other “sub device”.

So the driver enable to create a single device or lots of device with the same settings excepted the IP adresse for example.

…hummm, you’re right this way would certainly generate some recursion issue…

---

<div class="post-metadata">

**Author:** ![nifemi](https://avatars.discourse-cdn.com/v4/letter/n/a5b964/32.png) [@nifemi](https://forum.inductiveautomation.com/u/nifemi)\
**Post date:** [February 15, 2018, 3:19pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/9 "2018-02-15T15:19:54Z")

</div>

Sounds like you may have to create two different modules, with your “device model” module depending on the device module itself

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 15, 2018, 5:11pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/10 "2018-02-15T17:11:52Z")

</div>

Consider making a separate PersistentRecord type for the model and use a foreign key in your device’s PersistentRecord to reference it. Then create a set of regular config pages to list and edit your models. Have an option in those config pages to create multiple devices from a model. And in the devices, have a drop-down to select or change which model is used.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [February 15, 2018, 6:21pm UTC](https://forum.inductiveautomation.com/t/create-a-device-with-sdk/16968/11 "2018-02-15T18:21:42Z")

</div>

Thanks for this solution.
