3.Dweeting sensor values
Dweeting sensor values on dweet.io
This is also HTTP
communication between launchpad and cloud server dweet.io. Dweet.io is simple
publishing and subscribing for machines, sensors, devices, robots, and gadgets
(we just call them things). We call published messages ‘dweets’. It’s helpful
to think of dweet.io as a Twitter for things, in fact. We have to specify a
thing name that must unique. Another advantage of this is for dweet operation
we don’t want to sign up for an account. In this the sensor data are sending as
datasources .
sample Energia code
//#include <SPI.h>
#ifndef __CC3200R1M1RGC__
#endif
#include <WiFi.h>
// your network name also called SSID
char ssid[] = "**********";
// your network password
char password[] = "***********";
int status = WL_IDLE_STATUS;
IPAddress server(54,88,231,110); // dweet
// Initialize the client library
// Dweet parameters
#define thing_name "**********"
WiFiClient client;
int sample=0;
int sample2=0;
void setup() {
Serial.begin(9600);
pinMode(6, INPUT);
pinMode(2, INPUT);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(300);
}
Serial.println("\nYou're connected to the network");
Serial.println("Waiting for an ip address");
while (WiFi.localIP() == INADDR_NONE) {
// print dots while we wait for an ip addresss
Serial.print(".");
delay(300);
}
// if you get a connection, report back via serial:
}
void loop() {
sample=analogRead(2);
sample2=analogRead(6);
if (client.connect(server, 80)) {
Serial.println("connected");
Serial.print(F("Sending request... "));
client.print(F("GET /dweet/for/"));
client.print(thing_name);
client.print(F("?sample="));
client.print(sample);
client.print(F("&sample2="));
client.print(sample2);
client.println(F(" HTTP/1.1"));
client.println(F("Host: dweet.io"));
client.println(F("Connection: close"));
client.println(F(""));
Serial.println(F("done."));
}
else {
Serial.println(F("Connection failed"));
return;
}
Serial.println(F("Reading answer..."));
while (client.connected()) {
while (client.available()) {
char c = client.read();
Serial.print(c);
}
}
Serial.println(F(""));
delay(400);
}
Comments
Post a Comment