#include <WiFi.h>//library for wifi
void callback(char* subscribetopic, byte* payload, unsigned int payloadLength);
//-------credentials of IBM Accounts------
#define ORG "j5esuv"//IBM ORGANITION ID
#define DEVICE_TYPE "abcd"//Device type mentioned in ibm watson IOT Platform
#define DEVICE_ID "1234"//Device ID mentioned in ibm watson IOT Platform
#define TOKEN "12345678" //Token
String data3;
//-------- Customise the above values --------
char server[] = ORG ".messaging.internetofthings.ibmcloud.com";// Server Name
char publishTopic[] = "iot-2/evt/Data/fmt/json";// topic name and type of event perform and format in which data to be send
char subscribetopic[] = "iot-2/cmd/command/fmt/String";// cmd REPRESENT command type AND COMMAND IS TEST OF FORMAT STRING
char authMethod[] = "use-token-auth";// authentication method
char token[] = TOKEN;
char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;//client id
//-----------------------------------------
WiFiClient wifiClient; // creating the instance for wificlient
int t_p=5;
int e_p=18;
float ss=0.034;
long durn;
float dist_cm;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(t_p, OUTPUT);
pinMode(e_p, INPUT);;
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(t_p, LOW); // this speeds up the simulation
delayMicroseconds(2);
digitalWrite(t_p, HIGH);
delayMicroseconds(10);
digitalWrite(t_p, LOW);
durn=pulseIn(e_p,HIGH);
dist_cm=durn*ss/2;
Serial.print("distance=");
Serial.println(dist_cm);
delay(1000);
}