Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. /*
  2. This sketch sends data via HTTP GET requests to data.sparkfun.com service.
  3.  
  4. You need to get streamId and privateKey at data.sparkfun.com and paste them
  5. below. Or just customize this script to talk to other HTTP servers.
  6.  
  7. */
  8.  
  9. #include <ESP8266WiFi.h>
  10.  
  11. #include <Wire.h>
  12. #include <Adafruit_Sensor.h>
  13. #include <Adafruit_LSM303_U.h>
  14. #include <Adafruit_L3GD20_U.h>
  15. #include <Adafruit_9DOF.h>
  16.  
  17. /* Assign a unique ID to the sensors */
  18. Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
  19. Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
  20. Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
  21.  
  22. const char* ssid = "GTother";
  23. const char* password = "GeorgeP@1927";//"abcdefghij";
  24.  
  25. const char* host = "13.66.60.29";//"143.215.103.245";//"ec2-34-205-55-215.compute-1.amazonaws.com";//143.215.103.245";//"
  26. const char* streamId = "....................";
  27. const char* privateKey = "....................";
  28. float data[8];
  29. WiFiClient client;
  30. float arr[500];
  31. int ind = 0;
  32. String urlget = "";
  33. bool canSend = false;
  34.  
  35. void sensorsBegin()
  36. {
  37. Serial.begin(115200);
  38. Serial.println(F("Adafruit 9DOF Tester")); Serial.println("");
  39.  
  40. /* Initialise the sensors */
  41. if (!accel.begin())
  42. {
  43. /* There was a problem detecting the ADXL345 ... check your connections */
  44. Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
  45. while (1);
  46. }
  47. if (!mag.begin())
  48. {
  49. /* There was a problem detecting the LSM303 ... check your connections */
  50. Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
  51. while (1);
  52. }
  53. if (!gyro.begin())
  54. {
  55. /* There was a problem detecting the L3GD20 ... check your connections */
  56. Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
  57. while (1);
  58. }
  59. }
  60. void getSensorData(void)
  61. {
  62. /* Get a new sensor event */
  63. sensors_event_t event;
  64. data[0] = (float) millis();
  65. /* Display the results (acceleration is measured in m/s^2) */
  66. accel.getEvent(&event);
  67. data[1] = event.acceleration.x;
  68. data[2] = event.acceleration.y;
  69. data[3] = event.acceleration.z;
  70. mag.getEvent(&event);
  71. data[4] = event.magnetic.x;
  72. gyro.getEvent(&event);
  73. data[5] = event.gyro.x;
  74. data[6] = event.gyro.y;
  75. data[7] = event.gyro.z;
  76. /*for (int i = 0; i < 8; i++) {
  77. Serial.print(data[i]);
  78. Serial.print(",");
  79. }
  80. Serial.println();*/
  81. }
  82.  
  83. void setup() {
  84.  
  85. Serial.begin(115200);
  86. sensorsBegin();
  87. delay(10);
  88. // We start by connecting to a WiFi network
  89.  
  90. Serial.println();
  91. Serial.println();
  92. Serial.print("Connecting to ");
  93. Serial.println(ssid);
  94.  
  95. /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
  96. would try to act as both a client and an access-point and could cause
  97. network-issues with your other WiFi-devices on your WiFi-network. */
  98. WiFi.mode(WIFI_STA);
  99. WiFi.begin(ssid, password);
  100.  
  101. while (WiFi.status() != WL_CONNECTED) {
  102. delay(500);
  103. Serial.print(".");
  104. }
  105.  
  106.  
  107. Serial.println("");
  108. Serial.println("WiFi connected");
  109. Serial.println("IP address: ");
  110. Serial.println(WiFi.localIP());
  111. Serial.println(WiFi.macAddress());
  112. Serial.print("connecting to ");
  113. Serial.println(host);
  114. const int httpPort = 9999;
  115. //Serial.println(urlget);
  116. if (!client.connect(host, httpPort)) {
  117. Serial.println("connection failed");
  118. return;
  119. }
  120. canSend = true;
  121. }
  122.  
  123. int value = 0;
  124. //void loop () {}
  125. void loop() {
  126. if (canSend) {
  127. long tim = millis();
  128. getSensorData();
  129. //Serial.println();
  130. client.write((uint8_t*)data, sizeof(float) * 8);
  131. Serial.println(millis() - tim);
  132. //Serial.println("pls");
  133. }
  134.  
  135.  
  136. //Serial.println();
  137. //Serial.println("closing connection");
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement