lasote/weather
2 |
3 | ### What is it?
4 | An Arduino client to check an online [weather service][1].
5 | It uses [`lasote/arduino_http`][2] block for access service, so it can be used with any hardware adaptor.
6 | WeatherClient can check current weather and forecast of X future days.
7 |
8 | ### How can i use it?
9 | * Instance hardware client and init weather_client
10 | * Setup hardware
11 | * Call to get_weather
12 |
13 |
14 | //Our hardware adapter is Enc28J60 HanRun module
15 | EthernetClient client;
16 |
17 | //Instance a weather client for check weather
18 | WeatherClient weather_client(client, Serial);
19 |
20 | //LOOP
21 | bool ret = weather_client.get_weather(w, city, future_days);
22 | if(ret){
23 | Serial.println(w.description); Serial.print(F("Max temp:"));
24 | Serial.println(w.max_temp); Serial.print(F("Min temp:"));
25 | Serial.println(w.min_temp);
26 | }
27 |
28 | Check the full example in examples/main.cpp file!
29 |
30 | Enjoy it!!!
31 |
32 |
33 | [1]: http://openweathermap.org/
34 | [2]: https://www.biicode.com/lasote/blocks/lasote/arduino_http/branches/master
35 |
--------------------------------------------------------------------------------
/lasote/arduino_http/example/post.cpp:
--------------------------------------------------------------------------------
1 | #include "Arduino.h"
2 | #include "ntruchsess/arduino_uip/uipethernet.h"
3 | #include "lasote/arduino_http/http_client.h"
4 | #include "lasote/stream_finder_processor/stream_finder_processor.h"
5 | #include "lasote/stream_recorder/stream_recorder.h"
6 |
7 | using namespace lasote;
8 |
9 | EthernetClient client;
10 | char response_buffer[20];
11 | StreamRecorderProcessor response_recorder(response_buffer, 20); //Capture response in buffer
12 | HttpClient http_client(client, Serial);
13 | int led = 12;
14 |
15 | // the setup routine runs once when you press reset:
16 | void setup() {
17 | Serial.begin(9600);
18 | Serial.println("************* SETUP ****************");
19 | pinMode(led, OUTPUT); // initialize the digital pin as an output.
20 | uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
21 | Ethernet.begin(mac);
22 | http_client.processors.add_item(&response_recorder);
23 |
24 | }
25 |
26 | // the loop routine runs over and over again forever:
27 | void loop() {
28 |
29 | delay(5000);
30 | Serial.println("--- SENDING POST---");
31 |
32 | http_client.reset(); //Reset processors and custom headers
33 | //We can add custom headers to the request
34 | http_client.add_custom_header("Content-Type", "application/json");
35 |
36 | int sent = http_client.post(IPAddress(192, 168, 1, 100), "/", "{\"uno\":1, \"dos\":[2,2,2,2]}", 8080);
37 | if(sent){
38 | if(short int ret_code = http_client.receive()){
39 | if(ret_code == 200){
40 | Serial.println("Code 200 OK!");
41 | Serial.println(response_buffer);
42 | }
43 | else{
44 | Serial.print("Http Error:");
45 | Serial.println(ret_code);
46 | }
47 | }
48 | else{
49 | Serial.println(F("Error receiving!"));
50 | }
51 | }
52 | else{
53 | Serial.println(F("ERROR CONNECTING... retrying"));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/lasote/arduino_http/example/item_detector.cpp:
--------------------------------------------------------------------------------
1 | #include "Arduino.h"
2 | #include "ntruchsess/arduino_uip/uipethernet.h"
3 | #include "lasote/arduino_http/http_client.h"
4 | #include "lasote/stream_finder_processor/stream_finder_processor.h"
5 |
6 | using namespace lasote;
7 |
8 |
9 | int led = 13;
10 | EthernetClient client;
11 | HttpClient http_client(client, Serial);
12 | StreamFinderProcessor item_finder("MicroSD", "64GB", 50);
13 |
14 |
15 |
16 | // the setup routine runs once when you press reset:
17 | void setup() {
18 | Serial.begin(9600);
19 | Serial.println(F("************* SETUP ****************"));
20 | pinMode(led, OUTPUT); // initialize the digital pin as an output.
21 | uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
22 | Ethernet.begin(mac);
23 |
24 | http_client.processors.add_item(&item_finder);
25 |
26 | Serial.print(F("localIP: "));
27 | Serial.println(Ethernet.localIP());
28 | Serial.print(F("subnetMask: "));
29 | Serial.println(Ethernet.subnetMask());
30 | Serial.print(F("gatewayIP: "));
31 | Serial.println(Ethernet.gatewayIP());
32 | Serial.print(F("dnsServerIP: "));
33 | Serial.println(Ethernet.dnsServerIP());
34 |
35 | }
36 |
37 |
38 | void loop() {
39 |
40 | //Reset status and processors for new clean website check
41 | http_client.reset();
42 | delay(4000);
43 | Serial.println(F("---Checking website!---"));
44 | int ret = http_client.get("bargainshop.es", "/");
45 | if(ret){
46 | Serial.println("Connected");
47 | int ret_code = http_client.receive();
48 | if(ret_code==200){
49 | Serial.println(F("Page loaded ok..."));
50 | if(item_finder.found){
51 | Serial.println(F("MicroSD 64GB Found!"));
52 | }
53 | else{
54 | Serial.println(F("No MicroSD 64GB today"));
55 | }
56 |
57 | }
58 | else{
59 | Serial.println(F("Error code!"));
60 | }
61 | }
62 | else{
63 | Serial.println(F("ERROR CONNECTING... retrying"));
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/lasote/weather/examples/main.cpp:
--------------------------------------------------------------------------------
1 | #include "Arduino.h"
2 | #include "ntruchsess/arduino_uip/uipethernet.h"
3 | #include
lasote/arduino_http
2 |
3 | ### What is it?
4 | This is a simple but powerfull Arduino Client library. It works with low memory requirements using processors based on streaming text recognition. Only stores the very necessary data for work. Supports GET and POST requests.
5 |
6 | ### Tested on
7 |
8 | Its tested using a cheap Ethernet Enc28j60 module.
9 |
10 | HttpClient can work with other adapters that implements Client interface.
11 |
12 | | **Board** | 15 |**Example** | 16 |
| Enc28j60 no-shield | 19 |here | 20 |
| Adafruit Wifi cc3000 | 23 | How to instance a client here. Complete example coming soon... |
24 |
| Arduino Ethernet Shield | 27 |Coming soon... | 28 |
| Arduino Wifi Shield | 31 |Coming soon... | 32 |
| **Name** | 73 |**Description** | 74 |**Include** | 75 |
| StreamJsonProcessor | 78 |Parse json from http response. You have an example in arduino_weather project. Based on StreamJsonReader |
79 | #include "lasote/stream_processor/stream_json_processor.h" | 80 |
| StreamFinderProcessor | 83 |Checks if a string in exists in a response. Based on a StreamFinder. Check the menu_detector example in block home page | 84 |#include "lasote/stream_finder_processor/stream_finder_processor.h" | 85 |
| StreamRecorderProcessor | 88 |Just record the whole response in a buffer. Check the post example | 89 |#include "lasote/stream_recorder/stream_recorder.h" | 90 |