Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This sketch sends data via HTTP GET requests to data.sparkfun.com service.
- You need to get streamId and privateKey at data.sparkfun.com and paste them
- below. Or just customize this script to talk to other HTTP servers.
- */
- #include <ESP8266WiFi.h>
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_LSM303_U.h>
- #include <Adafruit_L3GD20_U.h>
- #include <Adafruit_9DOF.h>
- /* Assign a unique ID to the sensors */
- Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
- Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
- Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
- const char* ssid = "GTother";
- const char* password = "GeorgeP@1927";//"abcdefghij";
- const char* host = "13.66.60.29";//"143.215.103.245";//"ec2-34-205-55-215.compute-1.amazonaws.com";//143.215.103.245";//"
- const char* streamId = "....................";
- const char* privateKey = "....................";
- float data[8];
- WiFiClient client;
- float arr[500];
- int ind = 0;
- String urlget = "";
- bool canSend = false;
- void sensorsBegin()
- {
- Serial.begin(115200);
- Serial.println(F("Adafruit 9DOF Tester")); Serial.println("");
- /* Initialise the sensors */
- if (!accel.begin())
- {
- /* There was a problem detecting the ADXL345 ... check your connections */
- Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
- while (1);
- }
- if (!mag.begin())
- {
- /* There was a problem detecting the LSM303 ... check your connections */
- Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
- while (1);
- }
- if (!gyro.begin())
- {
- /* There was a problem detecting the L3GD20 ... check your connections */
- Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
- while (1);
- }
- }
- void getSensorData(void)
- {
- /* Get a new sensor event */
- sensors_event_t event;
- data[0] = (float) millis();
- /* Display the results (acceleration is measured in m/s^2) */
- accel.getEvent(&event);
- data[1] = event.acceleration.x;
- data[2] = event.acceleration.y;
- data[3] = event.acceleration.z;
- mag.getEvent(&event);
- data[4] = event.magnetic.x;
- gyro.getEvent(&event);
- data[5] = event.gyro.x;
- data[6] = event.gyro.y;
- data[7] = event.gyro.z;
- /*for (int i = 0; i < 8; i++) {
- Serial.print(data[i]);
- Serial.print(",");
- }
- Serial.println();*/
- }
- void setup() {
- Serial.begin(115200);
- sensorsBegin();
- delay(10);
- // We start by connecting to a WiFi network
- Serial.println();
- Serial.println();
- Serial.print("Connecting to ");
- Serial.println(ssid);
- /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
- would try to act as both a client and an access-point and could cause
- network-issues with your other WiFi-devices on your WiFi-network. */
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- Serial.println(WiFi.macAddress());
- Serial.print("connecting to ");
- Serial.println(host);
- const int httpPort = 9999;
- //Serial.println(urlget);
- if (!client.connect(host, httpPort)) {
- Serial.println("connection failed");
- return;
- }
- canSend = true;
- }
- int value = 0;
- //void loop () {}
- void loop() {
- if (canSend) {
- long tim = millis();
- getSensorData();
- //Serial.println();
- client.write((uint8_t*)data, sizeof(float) * 8);
- Serial.println(millis() - tim);
- //Serial.println("pls");
- }
- //Serial.println();
- //Serial.println("closing connection");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement