Please create a custom subscription in pub sub using cloud console.
In the code try something like this.
PCollection<TableRow> datastream = p.apply(PubsubIO.Read.named("Read device iot data from PubSub")
.subscription(String.format("projects/%s/subscriptions/%s",<ProjectId>,<Subscriptionname>))
.timestampLabel("ts")
.withCoder(TableRowJsonCoder.of()));
Please note when you subscribe , you can subscribe to either a topic or subscription name.
In the above code i subscribed to subscription which i created explicitly in pub sub console.
The advantage of going for explicit subscription is that, it stores data pulled from pub sub even when your data flow code is offline.So data wont be lost.