Skip to content

Instantly share code, notes, and snippets.

@Kazu-zamasu
Created August 2, 2016 06:08
Show Gist options
  • Select an option

  • Save Kazu-zamasu/e46bd4fd3debc71b2f7195584f3bd3e5 to your computer and use it in GitHub Desktop.

Select an option

Save Kazu-zamasu/e46bd4fd3debc71b2f7195584f3bd3e5 to your computer and use it in GitHub Desktop.
#include "mbed.h"
#include "HDC1000.h"
#include "SakuraAlpha.h"
HDC1000 hmtp(dp5,dp27);
AnalogIn SoilAI(dp13);
AnalogIn LuxAI(dp4);
SakuraAlphaI2C sakura(dp5, dp27); // sda, scl
Serial pc(USBTX, USBRX);
char Head[] = "{\"module\": \"hogehogehoge\",\"type\": \"channels\",\"datetime\":\"2016-06-01T12:21:11.628907163Z\",\"payload\": {\"channels\": [";
char Ch1Head[] = "{\"channel\":1,\"type\": \"i\",\"value\":";
char Ch2Head[] = "{\"channel\":2,\"type\": \"i\",\"value\":";
char Ch3Head[] = "{\"channel\":3,\"type\": \"f\",\"value\":";
char Ch4Head[] = "{\"channel\":4,\"type\": \"f\",\"value\":";
char JSONCHEND [] = "},";
char JSONSTREND [] = "]}}";
float Soil,Lux,Temp,RH;
int main() {
pc.baud(115200);
pc.printf("Waiting to come online...\r\n");
for(;;){
if( sakura.getNetworkStatus() == 1 ) break;
pc.printf("No Connecting");
wait_ms(1000);
}
pc.printf("Connecting Now");
while(true){
hmtp.get();
//printf("Temp: %.2fc, Humid: %.2f, Light: %.0f mV, Soil: %.0f\r\n", hmtp.temperature(), hmtp.humidity(), meas, meas2);
//wait(2.0);
Soil = SoilAI.read() * 3300;// Soil sennsor Analog object
Lux = LuxAI.read() * 3300;// Lux Sensor Analog object
Temp = hmtp.temperature();// Temperature sensor Analog object
RH = hmtp.humidity();// Humidity sensor Anlog object
sakura.writeChannel(1,Soil);
sakura.writeChannel(2,Lux);
sakura.writeChannel(3,Temp);
sakura.writeChannel(4,RH);
// USB Serial output
// pc.printf("%s%s%.2f%s%s%.2f%s%s%.2f%s%s%.2f%s%s\r\n",Head,Ch1Head,Soil,JSONCHEND,Ch2Head,Lux,JSONCHEND,Ch3Head,Temp,JSONCHEND,Ch4Head,RH,JSONCHEND,JSONSTREND);
wait(3.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment