PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skrawool 0:3954a906acc2 1 /* mbed Microcontroller Library
skrawool 0:3954a906acc2 2 * Copyright (c) 2006-2013 ARM Limited
skrawool 0:3954a906acc2 3 *
skrawool 0:3954a906acc2 4 * Licensed under the Apache License, Version 2.0 (the "License");
skrawool 0:3954a906acc2 5 * you may not use this file except in compliance with the License.
skrawool 0:3954a906acc2 6 * You may obtain a copy of the License at
skrawool 0:3954a906acc2 7 *
skrawool 0:3954a906acc2 8 * http://www.apache.org/licenses/LICENSE-2.0
skrawool 0:3954a906acc2 9 *
skrawool 0:3954a906acc2 10 * Unless required by applicable law or agreed to in writing, software
skrawool 0:3954a906acc2 11 * distributed under the License is distributed on an "AS IS" BASIS,
skrawool 0:3954a906acc2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
skrawool 0:3954a906acc2 13 * See the License for the specific language governing permissions and
skrawool 0:3954a906acc2 14 * limitations under the License.
skrawool 0:3954a906acc2 15 */
skrawool 0:3954a906acc2 16 #ifndef MBED_LOCALFILESYSTEM_H
skrawool 0:3954a906acc2 17 #define MBED_LOCALFILESYSTEM_H
skrawool 0:3954a906acc2 18
skrawool 0:3954a906acc2 19 #include "platform/platform.h"
skrawool 0:3954a906acc2 20
skrawool 0:3954a906acc2 21 #if DEVICE_LOCALFILESYSTEM
skrawool 0:3954a906acc2 22
skrawool 0:3954a906acc2 23 #include "drivers/FileSystemLike.h"
skrawool 0:3954a906acc2 24 #include "platform/PlatformMutex.h"
skrawool 0:3954a906acc2 25
skrawool 0:3954a906acc2 26 namespace mbed {
skrawool 0:3954a906acc2 27 /** \addtogroup drivers */
skrawool 0:3954a906acc2 28 /** @{*/
skrawool 0:3954a906acc2 29
skrawool 0:3954a906acc2 30 FILEHANDLE local_file_open(const char* name, int flags);
skrawool 0:3954a906acc2 31
skrawool 0:3954a906acc2 32 class LocalFileHandle : public FileHandle {
skrawool 0:3954a906acc2 33
skrawool 0:3954a906acc2 34 public:
skrawool 0:3954a906acc2 35 LocalFileHandle(FILEHANDLE fh);
skrawool 0:3954a906acc2 36
skrawool 0:3954a906acc2 37 virtual int close();
skrawool 0:3954a906acc2 38
skrawool 0:3954a906acc2 39 virtual ssize_t write(const void *buffer, size_t length);
skrawool 0:3954a906acc2 40
skrawool 0:3954a906acc2 41 virtual ssize_t read(void *buffer, size_t length);
skrawool 0:3954a906acc2 42
skrawool 0:3954a906acc2 43 virtual int isatty();
skrawool 0:3954a906acc2 44
skrawool 0:3954a906acc2 45 virtual off_t lseek(off_t position, int whence);
skrawool 0:3954a906acc2 46
skrawool 0:3954a906acc2 47 virtual int fsync();
skrawool 0:3954a906acc2 48
skrawool 0:3954a906acc2 49 virtual off_t flen();
skrawool 0:3954a906acc2 50
skrawool 0:3954a906acc2 51 protected:
skrawool 0:3954a906acc2 52 virtual void lock();
skrawool 0:3954a906acc2 53 virtual void unlock();
skrawool 0:3954a906acc2 54 FILEHANDLE _fh;
skrawool 0:3954a906acc2 55 int pos;
skrawool 0:3954a906acc2 56 PlatformMutex _mutex;
skrawool 0:3954a906acc2 57 };
skrawool 0:3954a906acc2 58
skrawool 0:3954a906acc2 59 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
skrawool 0:3954a906acc2 60 *
skrawool 0:3954a906acc2 61 * This allows programs to read and write files on the same disk drive that is used to program the
skrawool 0:3954a906acc2 62 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
skrawool 0:3954a906acc2 63 * read and write files.
skrawool 0:3954a906acc2 64 *
skrawool 0:3954a906acc2 65 * @Note Synchronization level: Thread safe
skrawool 0:3954a906acc2 66 *
skrawool 0:3954a906acc2 67 * Example:
skrawool 0:3954a906acc2 68 * @code
skrawool 0:3954a906acc2 69 * #include "mbed.h"
skrawool 0:3954a906acc2 70 *
skrawool 0:3954a906acc2 71 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
skrawool 0:3954a906acc2 72 *
skrawool 0:3954a906acc2 73 * int main() {
skrawool 0:3954a906acc2 74 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
skrawool 0:3954a906acc2 75 * fprintf(fp, "Hello World!");
skrawool 0:3954a906acc2 76 * fclose(fp);
skrawool 0:3954a906acc2 77 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
skrawool 0:3954a906acc2 78 *
skrawool 0:3954a906acc2 79 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
skrawool 0:3954a906acc2 80 * struct dirent *p;
skrawool 0:3954a906acc2 81 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
skrawool 0:3954a906acc2 82 * printf("%s\n", p->d_name); // to stdout.
skrawool 0:3954a906acc2 83 * }
skrawool 0:3954a906acc2 84 * closedir(d);
skrawool 0:3954a906acc2 85 * }
skrawool 0:3954a906acc2 86 * @endcode
skrawool 0:3954a906acc2 87 *
skrawool 0:3954a906acc2 88 * @note
skrawool 0:3954a906acc2 89 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
skrawool 0:3954a906acc2 90 * on the Host computer. This means it is no longer accessible from the Host Computer.
skrawool 0:3954a906acc2 91 *
skrawool 0:3954a906acc2 92 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
skrawool 0:3954a906acc2 93 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
skrawool 0:3954a906acc2 94 */
skrawool 0:3954a906acc2 95 class LocalFileSystem : public FileSystemLike {
skrawool 0:3954a906acc2 96 // No modifiable state
skrawool 0:3954a906acc2 97
skrawool 0:3954a906acc2 98 public:
skrawool 0:3954a906acc2 99 LocalFileSystem(const char* n) : FileSystemLike(n) {
skrawool 0:3954a906acc2 100
skrawool 0:3954a906acc2 101 }
skrawool 0:3954a906acc2 102
skrawool 0:3954a906acc2 103 virtual FileHandle *open(const char* name, int flags);
skrawool 0:3954a906acc2 104 virtual int remove(const char *filename);
skrawool 0:3954a906acc2 105 virtual DirHandle *opendir(const char *name);
skrawool 0:3954a906acc2 106 };
skrawool 0:3954a906acc2 107
skrawool 0:3954a906acc2 108 } // namespace mbed
skrawool 0:3954a906acc2 109
skrawool 0:3954a906acc2 110 #endif
skrawool 0:3954a906acc2 111
skrawool 0:3954a906acc2 112 #endif
skrawool 0:3954a906acc2 113
skrawool 0:3954a906acc2 114 /** @}*/