Sodaq Mbili and wifibee

hi

I am new to SODAQ WIFI …
How do I send data to my own website using SODAQ WIFI ?

The URL which I have, except arguments like below:

http:/www.sitename.com?arg=1

Should I be using GET ?
Please throw some light on catching values and routing to a website.
I am stuck with this one …
Many thanks,
Barani !

? wifiBee.HTTPGet(“httpbin.org”, 80, “/get”, “iotdata”, code);

The HTTPGet method has the following definition:

bool HTTPGet(const String& server, const uint16_t port, const String& URI, 
    const String& headers, uint16_t& httpCode);

So in your case you would want to use something like this:

wifiBee.HTTPGet("www.sitename.com", 80, "/?arg=1", "", code);

The response code from that request will be written into the parameter code.

Hi Gabriel,

Thanks for your input.

I am using following code:
#include <Sodaq_WifiBee.h>

  ----- in the middle of the code ----

  wifiBee.init(BeeSerial, BEE_VCC, BEEDTR, BEECTS, 1024);
  wifiBee.connectionSettings(SSID, "", PASSWORD);
  uint16_t code = 0;
  wifiBee.HTTPGet("www.validsite.com/iot/index.asp", 80, "/?iotdata=" + code, "", code);

I am getting following message:

NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
lua: cannot open init.lua

wifi.setmode(wifi.STATION)
wifi.sta.config(“UPC637985”,“xxxxxxxx”)
wifi.sta.connect()
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|1|
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|1|
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|5|
Success: IP received
wifiConn=net.createConnection(net.TCP, false)
wifiConn:on(“connection”, function(s) print("|C|") end)
wifiConn:on(“reconnection”, function(s) print("|RC|") end)
wifiConn:on(“disconnection”, function(s) print("|DC|") end)
wifiConn:on(“sent”, function(s) print("|DS|") end)
wifiConn:on(“receive”, function(s, d) lastData=d print("|DR|") end)
wifiConn:connect(80,“www.validsite.com/iot/index.asp”)
DNS retry 1!
DNS retry 2!
DNS retry 3!
DNS retry 4!
DNS Fail!

Where should I look further ?
Perhaps a small working example might help …
thanks,

Regards,
Barani !

hi

I got little further with the testing.
Now I am getting below error
HTTP Error 400. The request hostname is invalid.

NodeMCU 0.9.5 build 20150318 powered by Lua 5.1.4
lua: cannot open init.lua

uart.write(0, “OK\r\n”)
OK
wifi.setmode(wifi.STATION)
wifi.sta.config(“UPC637985”,“xxxxxxx”)
wifi.sta.connect()
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|1|
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|1|
print("|" … “STS|” … wifi.sta.status() … “|”)
|STS|5|
Success: IP received
wifiConn=net.createConnection(net.TCP, false)
wifiConn:on(“connection”, function(s) print("|C|") end)
wifiConn:on(“reconnection”, function(s) print("|RC|") end)
wifiConn:on(“disconnection”, function(s) print("|DC|") end)
wifiConn:on(“sent”, function(s) print("|DS|") end)
wifiConn:on(“receive”, function(s, d) lastData=d print("|DR|") end)
wifiConn:connect(80,“http://www.validsite.com”)
|C|
sb=""
sb=sb…“GET”
sb=sb…" "
sb=sb…"/?iotdata=1"
sb=sb…" HTTP/1.1\r\n"
sb=sb…“HOST: "
sb=sb…“http://www.validsite.com
sb=sb…”:"
sb=sb…“80”
sb=sb…"\r\n"
sb=sb…“Accept: /\r\n”
sb=sb…"\r\n"
wifiConn:send(sb) sb=""
|DS|
|DR|
uart.write(0, “|” … “SOF|”) for i=1, lastData:len(), 1 do ua(0, string.format("%02X", lastData:byte(i))) end uart.write(0, “|EOF|”)
|SOF|485454502F312E31203430302042616420526571756573740D0A436F6E74656E742D547970653A20746578742F68746D6C3B20636861727365743D75732D61736369690D0A5365727665723A204D6963726F736F66742D485454504150492F322E300D0A446174653A205361742C2032332041707220323031362032323A33333A333520474D540D0A436F6E6E656374696F6E3A20636C6F73650D0A436F6E74656E742D4C656E6774683A203333340D0A0D0A3C21444F43545950452048544D4C205055424C494320222D2F2F5733432F2F4454442048544D4C20342E30312F2F454E2222687474703A2F2F7777772E77332E6F72672F54522F68746D6C342F7374726963742E647464223E0D0A3C48544D4C3E3C484541443E3C5449544C453E42616420526571756573743C2F5449544C453E0D0A3C4D45544120485454502D45515549563D22436F6E74656E742D547970652220436F6E74656E743D22746578742F68746D6C3B20636861727365743D75732D6173636969223E3C2F484541443E0D0A3C424F44593E3C68323E4261642052657175657374202D20496E76616C696420486F73746E616D653C2F68323E0D0A3C68723E3C703E48545450204572726F72203430302E20546865207265717565737420686F73746E616D6520697320696E76616C69642E3C2F703E0D0A3C2F424F44593E3C2F48544D4C3E0D0A|EOF|> wifiConn:close()

Power OFF
Result code: 400
Response:
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Sat, 23 Apr 2016 22:33:35 GMT
Connection: close
Content-Length: 334

Bad Request

Bad Request - Invalid Hostname


HTTP Error 400. The request hostname is invalid.

</HTML�

There some issue with the URL/URI that you are attempting to “GET” from.
It is difficult to say what the issue is exactly without seeing the exact details.

This is incorrect. Parameter 1 should is the host, parameter 2 the port, and parameter 3 is the location on the host and any REST parameters.

It should look something like this:

wifiBee.HTTPGet("www.validsite.com", 80, "/iot/index.asp?iotdata=123", "", code);

Hi

I got that right in my second post. Only Hostname is used now.
But now I get HTTP/1.1 400 Bad Request.

Does it related to too many bytes submitted ?
#define TEST_HEADERS “Accept: /\r\n”

To get understand this properly … does the WIFI calls the hostname with parameters ?
I capture the parameters in the webpage. Hope, I am on the right path ?

Result code: 400
Response:
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Sat, 23 Apr 2016 23:41:36 GMT
Connection: close
Content-Length: 334

Bad Request

Bad Request - Invalid Hostname


HTTP Error 400. The request hostname is invalid.

What is the actual host and page you are trying to connect to?

Hi Gabriel,

Thanks for all your answers so far.

I am using the following parameter:

hostname:
http://www.ezee-solutions.com/

parameter:
iot/capturerawdata.asp?iotdata=123

You should see the captured results under this:
http://www.ezee-solutions.com/iot/capturerawdata.asp

Regards,
Barani !

I’ve tested this and it works:

uint16_t code = 0;
wifiBee.HTTPGet("www.ezee-solutions.com", 80, "/iot/capturerawdata.asp?iotdata=321", "", code);

However, you will have issues reading the response. The response arrives in multiple packets and causes some issues with the available memory on the WifiBee.

You should look at modifying the response from your server to be a simple acknowledgement of success.

Many thanks Gabriel.

Indeed it works at my end as well.
I have removed some forward slashes and it works like a charm.

I don’t understand your remark with available memory.
From WIFI Bee … i only have one main piece of code, which you wrote above.
Could you please elaborate what should I modify ?
Sending data through iotdata= parameter should be limited ?

Thanks once again,

Regards,
Barani !

Hi Barani,

The basic process that the Wifibee library uses is this. The request is generated and sent to the server. The response from the server is saved in a buffer on the NodeMCU Wifibee module. That buffer is then read back to the MCU (Autonomo).

I’ve pushed some changes to the repository today:

In your particular use case you are receiving a very large response (30-60KB). This highlighted a few issues which I have addressed in today’s commits. The issues were due to the large size of the response. In this case, the response was actually being sent in multiple packets, something that previously was not being handled correctly. Also due to the length of data there was an issue with the watch dog timer on the NodeMCU resetting the board. There was also a few other time out problems.

Currently, only the first packet of the response is saved. This is mainly due to memory restrictions. I tried to concatenate the packets as they arrived, but this caused issues with running out of memory and with hitting the buffer size limitations of Lua. Previously I experimented with using the file storage on the NodeMCU to store the response, I may revisit this once again.

Ok. Thanks for the elaborate explanation.
I will modify the webpage to return simple acknowledgement of success.

Meanwhile, how do i modify the already added library. When I add new .ZIP files, it prompts error saying library already exists.

Regards,
Barani !

On the Windows platform the library files are stored at:
/Users//Documents/Arduino/libraries

You can replace the files in the Sodaq_WifiBee subfolder directly.
Alternatively you could clone the repository into that location.

Hello Gabriel,

I have posted a question over Air Quality Sensor.


I didn;t get any reply sofar. Can you please assist me with this.

Regards,
Barani !

I repeat my question once again below:-

Recently, I bought an air quality sensor v1.3 and a WIFIBEE from Sodaq to
try out.

For the Air Quality sensor … i uploaded code from below site.
My board is Sodaq autonomo, which I got during the workshop and i have
connected this sensor to A0.
http://www.seeedstudio.com/wiki/Grove_-_Air_Quality_Sensor

but it didn;t compile and gave error at this part
ISR(TIMER2_OVF_vect)

{
if(airqualitysensor.counter==122)//set 2 seconds as a detected duty
{

    airqualitysensor.last_vol=airqualitysensor.first_vol;
    airqualitysensor.first_vol=analogRead(A0);
    airqualitysensor.counter=0;
    airqualitysensor.timer_index=1;
    PORTB=PORTB^0x20;
}
else
{
    airqualitysensor.counter++;
}

}

Sorry about that, I actually created a quick, and somewhat dirty, fix a few weeks ago. I didn’t want to post it publicly as the original library is quite a mess and I didn’t have the time to fix it up properly.

I actually assumed that the person I sent it to was you, however, it seems that there was another person experiencing the exact same problem.

I’ll post a link after I upload it to github.

Here you go:

Thanks Gabriel.

I have been waiting for this for long.
I will test this and let you.

Regards,
Barani !

Hello Gabriel,

The Air Quality sensor works now.
Many thanks.

The only thing, which I want to adjust is to get the actual sensor value instead of 0, 1, 2 and 3.
Perhaps, I can adjust the return value in airqualitysensor.slope() and apply the calculation in the application itself.

Regards,
Barani !

Yes you should modify that function if you want a different output.

I believe it currently takes the raw analog reading and converts that into a value ranging from 0-3. I’m not sure how useful the raw analog reading is though.