Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Implement modem #66

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
75ab6e5
Modem design image
ed7coyne Feb 10, 2016
478ff04
modified diagram
ed7coyne Feb 10, 2016
20e256d
renamed diagram
ed7coyne Feb 10, 2016
d9a2915
Create design.md
ed7coyne Feb 10, 2016
545ce38
Update design.md
ed7coyne Feb 10, 2016
1760354
Updated diagram
ed7coyne Feb 16, 2016
71803c7
Update design.md
ed7coyne Feb 16, 2016
c99734b
switched diagram back to png
ed7coyne Feb 16, 2016
a427d7e
Untested initial command with tests
ed7coyne Feb 17, 2016
b975f3b
Added gmock/gtest submodules
ed7coyne Feb 23, 2016
9e45a49
Revert "Added gmock/gtest submodules"
ed7coyne Feb 23, 2016
292885c
Added googletest submodule
ed7coyne Feb 23, 2016
9901db5
import example make file
ed7coyne Feb 23, 2016
f786598
Merge branch 'master' of https://github.com/ed7coyne/firebase-arduino…
ed7coyne Feb 23, 2016
6de7f81
Added *Ptr methods to firebase, get test mostly compiling
ed7coyne Feb 25, 2016
2723c05
Broke FirebaseHttpClient out from Firebase to allow greater portabili…
ed7coyne Feb 25, 2016
1ef1d06
# This is a combination of 2 commits.
ed7coyne Mar 18, 2016
bc4a518
Fix parsing of returned json object.
ed7coyne Mar 18, 2016
c03e474
Update serial_protocol.md
ed7coyne Feb 16, 2016
f07c84a
switched variable marker from $ to %%
ed7coyne Apr 8, 2016
54cd2a3
upgrade library to 1.5 style, import arduino-json-5.1.1 and start par…
ed7coyne Apr 8, 2016
2c6cab1
# This is a combination of 3 commits.
ed7coyne Feb 10, 2016
2eaf813
Modem design image
ed7coyne Feb 10, 2016
7a5c827
Untested initial command with tests
ed7coyne Feb 17, 2016
3d03b52
Add base for SerialTransciever.
ed7coyne Mar 12, 2016
ca715c8
Reorganized the library to comply with arduino 1.5+ library standards…
ed7coyne Apr 8, 2016
7c2c60c
Fixed some issues from PR review
ed7coyne Apr 15, 2016
9e52f85
post rebase cleanup, fix issues with ArduinoJson library
ed7coyne Apr 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "test/googletest"]
path = test/googletest
url = https://github.com/google/googletest.git
[submodule "test/arduino-mock"]
path = test/arduino-mock
url = https://github.com/ed7coyne/arduino-mock.git
13 changes: 8 additions & 5 deletions examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
// FirebasePush_ESP8266 is a sample that push a new timestamp to firebase
// on each reset.

#include <ESP8266WiFi.h>

#include <Firebase.h>

// create firebase client.
Firebase fbase = Firebase("example.firebaseio.com")
.auth("secret_or_token");
Firebase fbase("example.firebaseio.com")
.auth("secret_or_token");

void setup() {
Serial.begin(9600);
Expand All @@ -46,7 +48,7 @@ void setup() {
}

// print key.
Serial.println(push.name());
Serial.println("Name: " + push.name());

// get all entries.
FirebaseGet get = fbase.get("/logs");
Expand All @@ -55,8 +57,9 @@ void setup() {
Serial.println(push.error().message());
return;
}
// print json.
Serial.println(get.json());
// Print written timestamp.
String data = get.json()[push.name()];
Serial.println("Timestamp:" + data);
}

void loop() {
Expand Down
67 changes: 67 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/FirebaseSerialHost_ESP8266.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Copyright 2015 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


// A sample that will start our serial transciever listening on a software
// port and allow debug over the main serial port.
//
// A suggested setup for testing this example would be a USB to TTL cable
// with the green wire connected to pin 5 and the white wire connected to
// pin 4 (on the huzzah feather esp8266).
// First edit begin.txt and put in your host and secret.
// Then run the following commands to setup the serial port in linux:
// stty -F /dev/ttyUSB0 9600 raw -echo -echoe -echok
// Then on one console do:
// cat /dev/ttyUSB0 &
// This console will now read all responses from the modem. Then do:
// cat begin.txt > /dev/ttyUSB0
// You should see +OK and you can now feed in the other example commmands.

#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>

#include <Firebase.h>
#include <SerialTransceiver.h>

SoftwareSerial data_serial(5 /*RX*/, 4/*TX*/);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by default we should be using the default Serial so that it work with most board over usb (and thru the Arduino IDE).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I am not sure I agree. If we are showing an example of setting up a SerialHost I think the main serial line should be debug back to the user and we should provide the secondary line as data serial. That way they can easily the sample with other devices (rpi, arduino, etc..), which is the main purpose of the class. Although this may just be my ignorance, are there pins that also access the main serial line? I assumed it only went to usb.
Otherwise we are only demonstrating how to talk to themselves.

firebase::modem::SerialTransceiver transceiver;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if Arduino folks are that familiar with namespace, maybe we should provider a small arduino wrapper that typedef it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re organized the files a bit and added a using directive for it.


void setup() {
Serial.begin(9600);

// connect to wifi.
WiFi.begin("SSID", "PASSWORD");
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());

data_serial.begin(9600);
while (!data_serial) {
Serial.println("Error initilizing serial.");
delay(5000);
}

transceiver.begin(&data_serial);
}

void loop() {
transceiver.loop();
}
2 changes: 2 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/begin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BEGIN $YOUR_HOST $YOUR_SECRET

2 changes: 2 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/begin_stream.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BEGIN_STREAM /serial/test

2 changes: 2 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/end_stream.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
END_STREAM

2 changes: 2 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/get.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET /serial/test

1 change: 1 addition & 0 deletions examples/FirebaseSerialHost_ESP8266/get_push.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GET /serial/push_test
1 change: 1 addition & 0 deletions examples/FirebaseSerialHost_ESP8266/push.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PUSH /seria/push_test "this is a test string \ "
1 change: 1 addition & 0 deletions examples/FirebaseSerialHost_ESP8266/remove.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REMOVE /serial/test
2 changes: 2 additions & 0 deletions examples/FirebaseSerialHost_ESP8266/set.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SET /serial/test this is a test string \ "

7 changes: 4 additions & 3 deletions examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
// public Firebase and optionally display them on a OLED i2c screen.

#include <Firebase.h>
#include <ESP8266WiFi.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ArduinoJson.h>

#define OLED_RESET 10
#define OLED_RESET 3
Adafruit_SSD1306 display(OLED_RESET);

Firebase fbase("publicdata-cryptocurrency.firebaseio.com");
Expand All @@ -44,7 +45,7 @@ void setup() {
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
stream = fbase.stream("/bitcoin");
stream = fbase.stream("/bitcoin/last");
}


Expand All @@ -65,7 +66,7 @@ void loop() {
Serial.println(event);
JsonObject& json = buf.parseObject((char*)event.c_str());
String path = json["path"];
float data = json["data"];
float data = json["data"]["last"];

// TODO(proppy): parse JSON object.
display.clearDisplay();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_STORE
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Firebase_ESP8266-Neopixel is a sample that demonstrates how
// to set pixel data using a firebase stream.
#include <Firebase.h>
#include <ArduinoJson.h>

#include <Adafruit_NeoPixel.h>
#include "colors_ext.h"

const int PIN=13;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);

#define JSON_BUFFER_SIZE 10*4

// TODO: Replace with your own credentials and keep these safe.
Firebase fbase = Firebase("YOUR-PROJECT.firebaseio.com")
.auth("YOUR_AUTH_SECRET");

void setup() {
Serial.begin(9600);

strip.begin();
strip.setBrightness(25); // 0 ... 255
strip.show(); // Initialize all pixels to 'off'

// Not connected, set the LEDs red
colorWipe(&strip, 0xFF0000, 50);

// connect to wifi.
WiFi.begin("GoogleGuest", "");
Serial.print("connecting");

int count = 0;
while (WiFi.status() != WL_CONNECTED) {
// Draw rainbows while connecting
Serial.print(".");
if (count < strip.numPixels()){
strip.setPixelColor(count++, Wheel(&strip, count * 8));
strip.show();
}
delay(20);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());

// Connected, set the LEDs green
colorWipe(&strip, 0x00FF00, 50);
}


void loop() {
// Get all entries.
// TODO: Replace with streaming
FirebaseGet get = fbase.get("/rgbdata");
if (get.error()) {
Serial.println("Firebase get failed");
Serial.println(get.error().message());
return;
}

// Use dynamic for large JSON objects
// DynamicJsonBuffer jsonBuffer;
StaticJsonBuffer<JSON_OBJECT_SIZE(JSON_BUFFER_SIZE)> jsonBuffer;

// create an empty object
String ref = get.json();
Serial.println(ref);
JsonObject& pixelJSON = jsonBuffer.parseObject((char*)ref.c_str());

if(pixelJSON.success()){
for (int i=0; i < strip.numPixels(); i++) {
String pixelAddress = "pixel" + String(i);
String pixelVal = pixelJSON[pixelAddress];
Serial.println(pixelVal);
strip.setPixelColor(i, pixelVal.toInt());
}
strip.show();
} else {
Serial.println("Parse fail.");
Serial.println(get.json());
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// The following methods are extracted from the Adafruit Neopixel example, strandtest.
// https://github.com/adafruit/Adafruit_NeoPixel

#ifndef COLORS_EXT_H
#define COLORS_EXT_H

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(Adafruit_NeoPixel* strip, byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip->Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip->Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip->Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}



// Fill the dots one after the other with a color
void colorWipe(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip->numPixels(); i++) {
strip->setPixelColor(i, c);
strip->show();
delay(wait);
}
}

void rainbow(Adafruit_NeoPixel* strip, uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip->numPixels(); i++) {
strip->setPixelColor(i, Wheel(strip, (i+j) & 255));
}
strip->show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(Adafruit_NeoPixel* strip, uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip->numPixels(); i++) {
strip->setPixelColor(i, Wheel(strip, ((i * 256 / strip->numPixels()) + j) & 255));
}
strip->show();
delay(wait);
}
}

//Theatre-style crawling lights.
void theaterChase(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip->numPixels(); i=i+3) {
strip->setPixelColor(i+q, c); //turn every third pixel on
}
strip->show();

delay(wait);

for (int i=0; i < strip->numPixels(); i=i+3) {
strip->setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(Adafruit_NeoPixel* strip, uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip->numPixels(); i=i+3) {
strip->setPixelColor(i+q, Wheel(strip, (i+j) % 255)); //turn every third pixel on
}
strip->show();

delay(wait);

for (int i=0; i < strip->numPixels(); i=i+3) {
strip->setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
#endif
2 changes: 2 additions & 0 deletions examples/Firebase_ESP8266_LEDs/www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bower_components/
node_modules/
26 changes: 26 additions & 0 deletions examples/Firebase_ESP8266_LEDs/www/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Firebase Neopixel Web demo #

This demo console shows you how to synchronize data from the web to a device.

## Installation ##
The demo uses [Bower](http://bower.io/) and
[Polymer](http://www.polymer-project.org/) to simplify the UI and dependencies
of the project.

For Bower, you need to install [Node.js](http://nodejs.org/). After node is
installed, install the Bower package by calling:

`npm install -g bower`

After Bower is installed, you are ready to update the project dependencies with
Bower by running:

`bower install`

With the dependencies set, serve the www folder from a web server. For example,
you can use the Python Simple HTTP server module by running:

`python -m SimpleHTTPServer [port]`

With the web server running, navigate to /web-demo.html and you should see
the demo load.
Loading